944,112 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2329
  • C++ RSS
Jan 7th, 2005
0

Have an error in my program

Expand Post »
Ok, i know my program is probably all done incorrectly and thier are probably eaiser ways but, it works for me so.. I have an error and i cant find out what it is. Can anyone tell me?

C++ Syntax (Toggle Plain Text)
  1. //Game Project 1
  2.  
  3. #include <iostream.h>
  4. #include <conio.h>
  5. #include <iomanip.h>
  6. #include <stdlib.h>
  7.  
  8. main()
  9. {
  10. char weapon, head, chest, hands, legs, feet, name[21];
  11. int health, money, answer, shop_answer, fight_answer, weapon_answer;
  12. int armor_answer, potion_answer;
  13. health = 100;
  14. money = 0;
  15.  
  16. cout<<setw(40)<<"BLANK"<<endl;
  17. getch();
  18. system("CLS"); //Clears the Screen
  19. cout<<"Enter a name: ";
  20. cin.get(name, 21);
  21. cin.ignore(30,'\n');
  22. system("CLS"); //Clears the Screen
  23. {
  24. do
  25. {
  26. system("CLS"); //Clears the Screen
  27. cout<<setw(30)<<"---------"<<name<<"---------"<<endl;
  28. cout<<"\n";
  29. cout<<"---WEAPON--- "<<endl;
  30. cout<<"Weapon = "<<weapon<<endl;
  31. cout<<"\n";
  32. cout<<"---ARMOR--- "<<endl;
  33. cout<<"Head = "<<head<<endl;
  34. cout<<"Chest = "<<chest<<endl;
  35. cout<<"Hands = "<<hands<<endl;
  36. cout<<"Legs = "<<legs<<endl;
  37. cout<<"Feet = "<<feet<<endl;
  38. cout<<"\n";
  39. cout<<"---ITEMS---"<<endl;
  40. cout<<"Health "<<health<<endl;
  41. cout<<"Money $"<<money<<endl;
  42. getch();
  43.  
  44. system("CLS"); //Clears the Screen
  45. cout<<"---What would you like to do?---\n"<<endl;
  46. cout<<"1) Shop\n";
  47. cout<<"2) Fight\n";
  48. cout<<"3) See Stats\n";
  49. cout<<"Press 1, 2, or 3:\n ";
  50. cin>> answer;
  51. switch (answer)
  52. {
  53. case 1:
  54. system("CLS"); //Clears the Screen
  55. cout<<"---What would you like to buy?---\n";
  56. cout<<"1) Weapons\n";
  57. cout<<"2) Armor\n";
  58. cout<<"3) Health Potions\n";
  59. cout<<"Press 1, 2, or 3:\n ";
  60. cin>> shop_answer;
  61.  
  62. case 2:
  63. system("CLS"); //Clears the Screen
  64. cout<<"---Who do you want to fight?---\n";
  65. cout<<"1) A Man\n";
  66. cout<<"2) A Bandit\n";
  67. cout<<"3) A Knight\n";
  68. cout<<"4) A Dragon\n";
  69. cout<<"Press 1, 2, 3, or 4:\n ";
  70. cin>> fight_answer;
  71. switch (shop_answer)
  72. {
  73. case 1:
  74. system("CLS"); //Clears the Screen
  75. cout<<"---What type of Weapon do you want to buy?---\n";
  76. cout<<"1) Sword\n";
  77. cout<<"2) Bow\n";
  78. cout<<"3) Mace\n";
  79. cout<<"Press 1, 2, or 3:\n ";
  80. cin>> weapon_answer;
  81.  
  82. case 2:
  83. system("CLS"); //Clears the Screen
  84. cout<<"---For what part of body?---\n";
  85. cout<<"1) Head\n";
  86. cout<<"2) Chest\n";
  87. cout<<"3) Hands\n";
  88. cout<<"4) Legs\n";
  89. cout<<"5) Feet\n";
  90. cout<<"Press 1, 2, 3, 4, or 5:\n ";
  91. cin>> armor_answer;
  92.  
  93. case 3:
  94. system("CLS"); //Clears the Screen
  95. cout<<"---One potion costs 25 gold. are you sure you want to buy?\n";
  96. cout<<"1) Yes\n";
  97. cout<<"2) No\n";
  98. cout<<"Press 1 or 2:\n ";
  99. cin>> potion_answer;
  100. switch (potion_answer)
  101. {
  102. case 2:
  103. answer = 3;
  104. ////////SPACE////////////SPACE//////////////SPACE////////////SPACE///////////
  105. if ((potion_answer == 1) && (money >= 25))
  106. {
  107. health = health - 20;
  108. money = money - 25;
  109. answer = 3;
  110. {
  111. if ((potion_answer == 1) && (!(money >= 25)))
  112. {
  113. cout<<"You do not have enough money!\n";
  114. answer = 3;
  115.  
  116. }
  117. }while (answer == 3); //Loop again if answer is equal to 3.
  118. }
  119. getch();
  120. return 0;
  121. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Programmer88 is offline Offline
7 posts
since Jan 2005
Jan 7th, 2005
0

Re: Have an error in my program

From a quick glance, I'd guess it might be related to the missing breaks for each case. Would you mind describing the error?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jan 7th, 2005
0

Re: Have an error in my program

I dont think its the breaks because i didnt have them in before. There is an error that says "syntax error at end of input" I was thinking it had to do something with { or } somewhere. But ill keep looking and trying stuff out.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Programmer88 is offline Offline
7 posts
since Jan 2005
Jan 7th, 2005
0

Re: Have an error in my program

Uh, yeah. You have 9 opening braces { and 4 closing braces }. They need to be equal in number. Now is a good time to learn to match them up using proper indentation.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jan 7th, 2005
0

Re: Have an error in my program

ok thanks ill try that out
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Programmer88 is offline Offline
7 posts
since Jan 2005
Jan 7th, 2005
0

Re: Have an error in my program

yeah it worked thanks a lot!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Programmer88 is offline Offline
7 posts
since Jan 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: what is the best way to track segmentation fault errors
Next Thread in C++ Forum Timeline: why can't you use a switch statment with a string?





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


Follow us on Twitter


© 2011 DaniWeb® LLC