variable used without being initialized

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 2
Reputation: fraandres is an unknown quantity at this point 
Solved Threads: 0
fraandres fraandres is offline Offline
Newbie Poster

variable used without being initialized

 
0
  #1
31 Days Ago
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
  1. #include<iostream>
  2. #include<iomanip>
  3. using
  4. namespace std;
  5. #include<string>
  6. int main()
  7. {
  8. const double priceticket= 5.00;
  9. double numtick, percentage, total,revenue,balance,bonus;
  10. string charityname;
  11. cout<<"How many tickets were sold ? ";
  12. cin>>numtick;
  13. cin.ignore();
  14. if(numtick<=0)
  15.  
  16. cout<<"Invalid entry: there must be a positive number of tickets sold\n";
  17.  
  18. cout<<"What percentage of the ticket revenue goes to administrative costs?";
  19. cin>>percentage;
  20. cin.ignore();
  21. percentage=percentage/100;
  22. cout<<"How much total money is distributed in prizes ";
  23. cin>>total;
  24. cin.ignore();
  25. cout<<"What is the name of the charity ";
  26. getline(cin,charityname);
  27. cout<<fixed<<showpoint<<setprecision(2);
  28. revenue=numtick*priceticket;
  29. percentage=percentage*revenue;
  30. balance=revenue-percentage-total;
  31.  
  32. cout<<"Charity "<<setw(55)<<charityname<<endl;
  33. cout<<"Revenue generated from ticket sales: "<<setw(30)<<revenue<<endl;
  34. cout<<"Amount deducted for administrative overhead: "<<setw(22)<<percentage<<endl;
  35. cout<<"Amount deducted for prize money: "<<setw(34)<<total<<endl;
  36.  
  37. if(numtick < 10000)
  38. bonus=0;
  39. else if (numtick > 10000 && numtick <= 24999)
  40. bonus=3000;
  41. else if (numtick > 25000 && numtick <= 49999)
  42. bonus=8000;
  43. else if (numtick > 50000 && numtick <= 99999)
  44. bonus = 15000;
  45. else if (numtick >100,000)
  46. bonus= 25000;
  47.  
  48. cout<<"Bonus contribution: "<<setw(34)<<bonus<<endl;
  49. cout<<"Balance raised for charitable fund: "<<setw(31)<<balance<<endl;
  50. balance=bonus+balance;
  51. return 0;
  52. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 113
Reputation: abhi_elementx is an unknown quantity at this point 
Solved Threads: 6
abhi_elementx's Avatar
abhi_elementx abhi_elementx is offline Offline
Junior Poster
 
0
  #2
31 Days Ago
Originally Posted by fraandres View Post
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;
PEACE !
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,364
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #3
31 Days Ago
How about a final else?

And don't use the comma here:
  1. else if (numtick >100,000)
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC