getting a error saying the variable 'bonus' is being used without being initialized can anyone how do a initialized .... i just cant find a way

#include<iostream> 
#include<iomanip> 
using
namespace std; 
#include<string> 
int main() 
{
const double priceticket= 5.00; 
double numtick, percentage, total,revenue,balance,bonus; 
string charityname;
cout<<"How many tickets were sold ? "; 
cin>>numtick;
cin.ignore();
if(numtick<=0) 

cout<<"Invalid entry: there must be a positive number of tickets sold\n"; 

cout<<"What percentage of the ticket revenue goes to administrative costs?"; 
cin>>percentage;
cin.ignore();
percentage=percentage/100;
cout<<"How much total money is distributed in prizes "; 
cin>>total;
cin.ignore();
cout<<"What is the name of the charity "; 
getline(cin,charityname);
cout<<fixed<<showpoint<<setprecision(2);
revenue=numtick*priceticket;
percentage=percentage*revenue;
balance=revenue-percentage-total;

cout<<"Charity "<<setw(55)<<charityname<<endl; 
cout<<"Revenue generated from ticket sales: "<<setw(30)<<revenue<<endl; 
cout<<"Amount deducted for administrative overhead: "<<setw(22)<<percentage<<endl; 
cout<<"Amount deducted for prize money: "<<setw(34)<<total<<endl; 

if(numtick < 10000)
bonus=0;
else if (numtick > 10000 && numtick <= 24999) 
bonus=3000;
else if (numtick > 25000 && numtick <= 49999)
bonus=8000;
else if (numtick > 50000 && numtick <= 99999) 
bonus = 15000;
else if (numtick >100,000) 
bonus= 25000;

cout<<"Bonus contribution: "<<setw(34)<<bonus<<endl; 
cout<<"Balance raised for charitable fund: "<<setw(31)<<balance<<endl; 
balance=bonus+balance;
return 0; 
}

Recommended Answers

All 2 Replies

getting a error saying the variable 'bonus' is being used without being initialized can anyone how do a initialized .... i just cant find a way

initialize bonus as:
double numtick, percentage, total,revenue,balance, bonus = 0;

How about a final else?

And don't use the comma here:

else if (numtick >100,000)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.