•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,651 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,096 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1667 | Replies: 5 | Solved
![]() |
•
•
Join Date: Jan 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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?
//Game Project 1
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdlib.h>
main()
{
char weapon, head, chest, hands, legs, feet, name[21];
int health, money, answer, shop_answer, fight_answer, weapon_answer;
int armor_answer, potion_answer;
health = 100;
money = 0;
cout<<setw(40)<<"BLANK"<<endl;
getch();
system("CLS"); //Clears the Screen
cout<<"Enter a name: ";
cin.get(name, 21);
cin.ignore(30,'\n');
system("CLS"); //Clears the Screen
{
do
{
system("CLS"); //Clears the Screen
cout<<setw(30)<<"---------"<<name<<"---------"<<endl;
cout<<"\n";
cout<<"---WEAPON--- "<<endl;
cout<<"Weapon = "<<weapon<<endl;
cout<<"\n";
cout<<"---ARMOR--- "<<endl;
cout<<"Head = "<<head<<endl;
cout<<"Chest = "<<chest<<endl;
cout<<"Hands = "<<hands<<endl;
cout<<"Legs = "<<legs<<endl;
cout<<"Feet = "<<feet<<endl;
cout<<"\n";
cout<<"---ITEMS---"<<endl;
cout<<"Health "<<health<<endl;
cout<<"Money $"<<money<<endl;
getch();
system("CLS"); //Clears the Screen
cout<<"---What would you like to do?---\n"<<endl;
cout<<"1) Shop\n";
cout<<"2) Fight\n";
cout<<"3) See Stats\n";
cout<<"Press 1, 2, or 3:\n ";
cin>> answer;
switch (answer)
{
case 1:
system("CLS"); //Clears the Screen
cout<<"---What would you like to buy?---\n";
cout<<"1) Weapons\n";
cout<<"2) Armor\n";
cout<<"3) Health Potions\n";
cout<<"Press 1, 2, or 3:\n ";
cin>> shop_answer;
case 2:
system("CLS"); //Clears the Screen
cout<<"---Who do you want to fight?---\n";
cout<<"1) A Man\n";
cout<<"2) A Bandit\n";
cout<<"3) A Knight\n";
cout<<"4) A Dragon\n";
cout<<"Press 1, 2, 3, or 4:\n ";
cin>> fight_answer;
switch (shop_answer)
{
case 1:
system("CLS"); //Clears the Screen
cout<<"---What type of Weapon do you want to buy?---\n";
cout<<"1) Sword\n";
cout<<"2) Bow\n";
cout<<"3) Mace\n";
cout<<"Press 1, 2, or 3:\n ";
cin>> weapon_answer;
case 2:
system("CLS"); //Clears the Screen
cout<<"---For what part of body?---\n";
cout<<"1) Head\n";
cout<<"2) Chest\n";
cout<<"3) Hands\n";
cout<<"4) Legs\n";
cout<<"5) Feet\n";
cout<<"Press 1, 2, 3, 4, or 5:\n ";
cin>> armor_answer;
case 3:
system("CLS"); //Clears the Screen
cout<<"---One potion costs 25 gold. are you sure you want to buy?\n";
cout<<"1) Yes\n";
cout<<"2) No\n";
cout<<"Press 1 or 2:\n ";
cin>> potion_answer;
switch (potion_answer)
{
case 2:
answer = 3;
////////SPACE////////////SPACE//////////////SPACE////////////SPACE///////////
if ((potion_answer == 1) && (money >= 25))
{
health = health - 20;
money = money - 25;
answer = 3;
{
if ((potion_answer == 1) && (!(money >= 25)))
{
cout<<"You do not have enough money!\n";
answer = 3;
}
}while (answer == 3); //Loop again if answer is equal to 3.
}
getch();
return 0;
}![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Error in simple "Hello World" program (C++)
- error in the program (C)
- Linker Error when program is run (Urgent help required Please") (C++)
- Error in c++ program (C++)
Other Threads in the C++ Forum
- Previous Thread: what is the best way to track segmentation fault errors
- Next Thread: why can't you use a switch statment with a string?



Linear Mode