Help with if

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Help with if

 
0
  #1
Jul 16th, 2009
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string name;
  8. char indicator = 'c' ; // Input indicator
  9. char answer1,answer2,answer3,answer4,answer5;
  10. int count1,count2,count3,count4,count5;
  11. cout << " Welcome to Risk master, answer those 5 questions to calculate how risky your partner is";
  12. cout << " Rule : press Y for Yes, N for No, No space for the name " ;
  13. cout << " Enter name : " << endl;
  14. cin >> name ;
  15. while ( indicator == 'c' || indicator == 'C' )
  16. {
  17. cout << endl
  18. << " Income > 100k/year : " ;
  19. cin >> answer1;
  20. if (answer1 == 'y')
  21. {
  22. count1 =2 ;
  23. else
  24. count1 = 0 ;
  25. }
  26. cout << "Just have me to support : " ;
  27. cin >> answer2;
  28. if (answer2 == y)
  29. {
  30. count2 = 2;
  31. else
  32. count2 =0 ;
  33. }
  34. cout << "When we divorce, I am gonna get all the property? : " ;
  35. cin >> answer3;
  36. if (answer3 == y)
  37. {
  38. count3 = 2;
  39. else
  40. count3 =0 ;
  41. }
  42. cout << "When we hangout, You gonna pay for dating and dinner : " ;
  43. cin>> answer4;
  44. if (answer4 == y)
  45. {
  46. count4 = 2;
  47. else
  48. count4 =0;
  49. }
  50. cout << " Say yes for everything above: "
  51. cin>> answer5;
  52. if (answer5 == y)
  53. {
  54. count5 = 2;
  55. else
  56. count5 =0
  57. }
  58. total = count1+ count2+ count3+ count4+ count5;
  59. result = (total/10)*100;
  60. cout << " The rate for : " <<name << "is" << result << endl;
  61. cout << " Want to play another game : y/n"
  62. cin >> indicator;
  63. }
  64. system ("pause");
  65. return 0;
just try to make fun after watching the movie about the man who tries to calculate risk with software....
but don't know why its stuck... Any help?
Last edited by Se7Olutionyg; Jul 16th, 2009 at 12:14 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,660
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help with if

 
0
  #2
Jul 16th, 2009
>>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.
Last edited by Ancient Dragon; Jul 16th, 2009 at 12:46 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 59
Reputation: Dannyo329 is an unknown quantity at this point 
Solved Threads: 6
Dannyo329's Avatar
Dannyo329 Dannyo329 is offline Offline
Junior Poster in Training

Re: Help with if

 
0
  #3
Jul 16th, 2009
There's a Quite alot of Problems in there, for example in many places you put:

  1. if (answer1 == 'y')
  2. {
  3. count1 =2 ;
  4. else
  5. count1 = 0 ;
  6. }
You might have this problem :
expected primary-expression before "else"

That's not correct since you want it to be
  1. if
  2. {
  3. }
  4. //then
  5. else
  6. {
  7. }
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:
  1. if (answer2 == y)
You Forgot to add the ' ' (things(not speechmarks)) on around the y!
so the correct way is:
  1. if (answer2 == 'y')
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 programmers will get smashed by C++ programmers.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: Help with if

 
0
  #4
Jul 16th, 2009
but why the result after say yes and no is 0
if say yes everytime is 100 percent
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,660
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help with if

 
0
  #5
Jul 16th, 2009
Originally Posted by Se7Olutionyg View Post
but why the result after say yes and no is 0
if say yes everytime is 100 percent
how are you getting an executable program to run with all those compile errors? Most (maybe all) compilers do not produce the *.exe file until all errors are fixed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: Help with if

 
0
  #6
Jul 16th, 2009
oh, its running right now
just the resullt is not correct.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,660
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help with if

 
0
  #7
Jul 16th, 2009
***sigh***
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: Help with if

 
-1
  #8
Jul 16th, 2009
what?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 501
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Help with if

 
0
  #9
Jul 16th, 2009
Se7Olutionyg,
Read all post between #2 to #7
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,131
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Help with if

 
1
  #10
Jul 16th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 377 | Replies: 9
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC