| | |
variable used without being initialized
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
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)
#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; }
0
#3 31 Days Ago
How about a final else?
And don't use the comma here:
And don't use the comma here:
C++ Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Uninitialized local variable that HAS been initialized! (C++)
- static variable got initialized everytime (PHP)
- Create static variable in non static member function (C++)
- Local Variable not been Initialized (Java)
- error: variable might not have been initialized (Java)
- Need Help with variable initialization (Java)
Other Threads in the C++ Forum
- Previous Thread: How do you profile your C/C++ code ?
- Next Thread: I cant figure this out. Please help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






