Have an error in my program

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Have an error in my program

 
0
  #1
Jan 7th, 2005
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?

  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. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Have an error in my program

 
0
  #2
Jan 7th, 2005
From a quick glance, I'd guess it might be related to the missing breaks for each case. Would you mind describing the error?
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Re: Have an error in my program

 
0
  #3
Jan 7th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Have an error in my program

 
0
  #4
Jan 7th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Re: Have an error in my program

 
0
  #5
Jan 7th, 2005
ok thanks ill try that out
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Re: Have an error in my program

 
0
  #6
Jan 7th, 2005
yeah it worked thanks a lot!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC