User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Have an error in my program

  #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?

//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;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,615
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 142
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Have an error in my program

  #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  
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Re: Have an error in my program

  #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  
Join Date: Apr 2004
Posts: 3,615
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 142
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Have an error in my program

  #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  
Join Date: Jan 2005
Posts: 7
Reputation: Programmer88 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Programmer88 Programmer88 is offline Offline
Newbie Poster

Re: Have an error in my program

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

Re: Have an error in my program

  #6  
Jan 7th, 2005
yeah it worked thanks a lot!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC