943,559 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 497
  • C++ RSS
Jul 16th, 2009
0

Help with if

Expand Post »
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Jul 16th, 2009
0

Re: Help with if

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 16th, 2009
0

Re: Help with if

There's a Quite alot of Problems in there, for example in many places you put:

C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  1. if (answer2 == y)
You Forgot to add the ' ' (things(not speechmarks)) on around the y!
so the correct way is:
C++ Syntax (Toggle Plain Text)
  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!
Reputation Points: 20
Solved Threads: 8
Junior Poster in Training
Dannyo329 is offline Offline
79 posts
since Apr 2008
Jul 16th, 2009
0

Re: Help with if

but why the result after say yes and no is 0
if say yes everytime is 100 percent
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Jul 16th, 2009
0

Re: Help with if

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 16th, 2009
0

Re: Help with if

oh, its running right now
just the resullt is not correct.
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Jul 16th, 2009
0

Re: Help with if

***sigh***
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 16th, 2009
-1

Re: Help with if

what?
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Jul 16th, 2009
0

Re: Help with if

Se7Olutionyg,
Read all post between #2 to #7
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 16th, 2009
1

Re: Help with if

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.
Moderator
Reputation Points: 3275
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,716 posts
since May 2006

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: C++ with Excel Problem =(
Next Thread in C++ Forum Timeline: Initialise Array when size unknown





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


Follow us on Twitter


© 2011 DaniWeb® LLC