| | |
Help with if
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 101
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; int main() { string name; char indicator = 'c' ; // Input indicator char answer1,answer2,answer3,answer4,answer5; int count1,count2,count3,count4,count5; cout << " Welcome to Risk master, answer those 5 questions to calculate how risky your partner is"; cout << " Rule : press Y for Yes, N for No, No space for the name " ; cout << " Enter name : " << endl; cin >> name ; while ( indicator == 'c' || indicator == 'C' ) { cout << endl << " Income > 100k/year : " ; cin >> answer1; if (answer1 == 'y') { count1 =2 ; else count1 = 0 ; } cout << "Just have me to support : " ; cin >> answer2; if (answer2 == y) { count2 = 2; else count2 =0 ; } cout << "When we divorce, I am gonna get all the property? : " ; cin >> answer3; if (answer3 == y) { count3 = 2; else count3 =0 ; } cout << "When we hangout, You gonna pay for dating and dinner : " ; cin>> answer4; if (answer4 == y) { count4 = 2; else count4 =0; } cout << " Say yes for everything above: " cin>> answer5; if (answer5 == y) { count5 = 2; else count5 =0 } total = count1+ count2+ count3+ count4+ count5; result = (total/10)*100; cout << " The rate for : " <<name << "is" << result << endl; cout << " Want to play another game : y/n" cin >> indicator; } system ("pause"); return 0;
but don't know why its stuck... Any help?
Last edited by Se7Olutionyg; Jul 16th, 2009 at 12:14 am.
>>but don't know why its stuck
And what exactly does that mean?
There are a huge number of compiler error messages. Fix them one at a time -- fix an error, recompile, then fix the next error. Keep doing that until you have fixed all the errors and warnings.
And what exactly does that mean?
There are a huge number of compiler error messages. Fix them one at a time -- fix an error, recompile, then fix the next error. Keep doing that until you have fixed all the errors and warnings.
Last edited by Ancient Dragon; Jul 16th, 2009 at 12:46 am.
There's a Quite alot of Problems in there, for example in many places you put:
You might have this problem :
expected primary-expression before "else"
That's not correct since you want it to be
But you've added else in the block of if
. So the compiler would treat it as something else most likely.
(There's alot of places where you wrote it like that.
)
Also in:
You Forgot to add the ' ' (things(not speechmarks)) on around the y!
so the correct way is:
There's a few places with that mistake as well.
There's also places where you forgot to add the semicolon ";" on the end. I'm sure you can find those.
You also forgot to intialize your variables
: "result" and "total"
I recommend you intialize them as double or float when you do change it.
And there's something you forgot after "return 0".(its easy to find!
)
Hope this helped!
C++ Syntax (Toggle Plain Text)
if (answer1 == 'y') { count1 =2 ; else count1 = 0 ; }
expected primary-expression before "else"
That's not correct since you want it to be
C++ Syntax (Toggle Plain Text)
if { } //then else { }
. So the compiler would treat it as something else most likely.(There's alot of places where you wrote it like that.
)Also in:
C++ Syntax (Toggle Plain Text)
if (answer2 == y)
so the correct way is:
C++ Syntax (Toggle Plain Text)
if (answer2 == 'y')
There's also places where you forgot to add the semicolon ";" on the end. I'm sure you can find those.
You also forgot to intialize your variables
I recommend you intialize them as double or float when you do change it.
And there's something you forgot after "return 0".(its easy to find!
)Hope this helped!
C programmers will get smashed by C++ programmers.
Since we know the program you posted cannot possibly compile, and you claim it's actually running, you need to repost the current code you're compiling. And then explain in detail what the program if doing wrong. Don't make us search for it.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ with Excel Problem =(
- Next Thread: Initialise Array when size unknown
Views: 377 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






