syntax error at end of input

This is a discussion on syntax error at end of input within the C++ Programming forums, part of the General Programming Boards category; This is the most progress I've made on my RPG since I've started: Code: #include <cstdlib> #include <iostream> #include <ctime> ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    syntax error at end of input

    This is the most progress I've made on my RPG since I've started:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <ctime>
    using namespace std;
    void r1()                     //first territory
    {
    cout<<"You can move south or east. type h for help.";
    }
    
    int main(int argc, char *argv[])
    {
        char namen[100];
        int initial;
        int strength;
        int agility;
        int defense;
        char command;
        char west, east, north, south;
        
        cout<<"What would you like to do?";
        cout<<"\n1.New game\n2.Load game\n3.Exit\n"; //Menu
        cin>>initial;
        switch(initial){ //menu switch statment
        case 1:				
             cout<<"Enter your name:"; //ask for name
             cin>>namen;
             cout<<namen<<" is it. Alright then\n";
             cout<<"Enter your strength agility and defense again(must=20):\n";
             cin>>strength>>agility>>defense;
    	while(strength+agility+defense!=20){     //loop if str ag and def not 20
    	cout<<"Enter strength, agility, and defense(must=20):";
    	cin>>strength>>agility>>defense;
    	}
        break;
        case 2:                     //loading game
    		 cout<<"Not availiable yet";
    	system("PAUSE");
        break;
        case 3:          //exit
             return 0;
        break;
        default:          
             cout<<"error";        //default
        system("PAUSE");
        }
        //intro
        cout<<"                        Welcome to naushmien\n\n*Dramatic Music*\n\n";
        r1();
        for(int loop=0;loop<100;loop++){
    	cin>>command;
    	switch(command){
    	case 'a':
    	return 0;
    	break;
    	default:
    	cout<<"messed";
    	break;
    	}
        
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Surprisingly I fixed a lot of the errors myself
    The one I don't know how to fix is error at end of input. At first I thought it was because I had a never ending while loop.
    I was just trying to make some progress can you put a switch statment in a loop?
    I'm pretty proud of myself.
    Last edited by cerin; 03-05-2005 at 11:14 PM.
    My computer is awesome.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
        for(int loop=0;loop<100;loop++){
    	cin>>command;
    	switch(command){
    	case 'a':
    	return 0;
    	break;
    	default:
    	cout<<"messed";
    	break;
    	}
    You're missing a right brace to end this for-loop. You've got one for the switch(), but not for the for-loop.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Thanks for the help. I hate when I do stuff like that
    My computer is awesome.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Can I put a switch statement within a switch statement?
    This is my updated code:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <ctime>
    using namespace std;
    void to()                     //first territory
    {
    cout<<"You can move south or east. type h for help.";
    }
    
    int main(int argc, char *argv[])
    {
        char namen[100];
        int initial;
        int strength;
        int agility;
        int defense;
        char command;
        char direction;
        int n;
        
        cout<<"What would you like to do?";
        cout<<"\n1.New game\n2.Load game\n3.Exit\n"; //Menu
        cin>>initial;
        switch(initial){ //menu switch statment
        case 1:				
             cout<<"Enter your name:"; //ask for name
             cin>>namen;
             cout<<namen<<" is it. Alright then\n";
             cout<<"Enter your strength agility and defense again(must=20):\n";
             cin>>strength>>agility>>defense;
    	while(strength+agility+defense!=20){     //loop if str ag and def not 20
    	cout<<"Enter strength, agility, and defense(must=20):";
    	cin>>strength>>agility>>defense;
    	}
        break;
        case 2:                     //loading game
    		 cout<<"Not availiable yet";
    	system("PAUSE");
        break;
        case 3:          //exit
             return 0;
        break;
        default:          
             cout<<"error";        //default
        system("PAUSE");
        }
        //intro
        cout<<"                        Welcome to naushmien\n\n*Dramatic Music*\n\n";
        to();
        for(int loop=0;loop<100;loop++){  //main loop
    	cin>>command;
    	switch(command){
    	case 'm':                    //movement
    	cout<<"which way would you like to move?";
    	cin>>direction;
    	switch(direction){
    	case 'n':
    	return n+1;
    	cout<<n;
    	break;
    	}
    	break;
    	default:
    	cout<<"messed";
    	break;
    	}
    	}
        
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    What I'm trying to do is type m for move, ask which direction, n is for north. I want to add numbers to the directions so that it will change where you are in the world based on what the ints n, e, w, s equal. I would need the switch to change for each territory considering there has to be some end to the amount of territories I have so you can't go infinitely in one direction. Any ideas?
    My computer is awesome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 08:12 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. How can I read until the end of an input line?
    By Bad_Scooter in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2003, 09:29 PM
  5. Reading integers until end of input
    By nivo in forum C Programming
    Replies: 7
    Last Post: 10-20-2001, 04:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21