944,025 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2799
  • C++ RSS
Nov 4th, 2009
0

variable used without being initialized

Expand 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
C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fraandres is offline Offline
7 posts
since Nov 2009
Nov 4th, 2009
0
Re: variable used without being initialized
Click to Expand / Collapse  Quote originally posted by fraandres ...
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;
Reputation Points: 11
Solved Threads: 7
Junior Poster
abhi_elementx is offline Offline
118 posts
since Dec 2007
Nov 4th, 2009
0
Re: variable used without being initialized
How about a final else?

And don't use the comma here:
C++ Syntax (Toggle Plain Text)
  1. else if (numtick >100,000)
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How do you profile your C/C++ code ?
Next Thread in C++ Forum Timeline: I cant figure this out. Please help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC