Haveing trouble

This is a discussion on Haveing trouble within the C++ Programming forums, part of the General Programming Boards category; i have been trying to get this thig to work but ther are too many bugs can any mabey give ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    47

    Post Haveing trouble

    i have been trying to get this thig to work but ther are too many bugs can any mabey give me a couple of pointers or say what im doing wrong

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main () {
        int a,input,temp;
        int x = 1;
        
        while ( x != 1000000 ) {
        cout<<"This is my game !! \n";
        cout<<"Ok you have a potato. WOOT! What will you do with it? \n";
        cout<<"1) cook the potato \n";
        cout<<"2) Use the potato as a pilow and take a nap \n";
        cout<<"3) Try to become president? \n";
        cin>> input;
        switch ( input ) {
               case 1:
                    cout<<"For how long? /n";
                    cin>> temp;
                    if ( temp < 100 ); {
                         cout<<"potato is stall \n";
                         }
                    else if ( temp > 99 ),( temp < 200 ); {
                         cout<<"The potato will be semi cooked \n";
                         }
                    else if ( temp > 199 ),( temp < 300 ); {
                         cout<<"the potato is cooked well \n";
                         }
                    else if ( temp > 299 ),( temp < 500 ); {
                         cout<<"the potato was bernt \n";
                         }
                    else if ( temp > 499 ); {
                         cout<<"your house is on fire!! \n" <<"1) call 911 \n" <<"2) leave. \n" <<"3) stay in bulding"
                         cin>> input;
                         switch ( input ) {
                                case 1:
                                     cout<<"Thay save your house steal you good stuff and charg you money for it!?!? \n";
                                     break;
                                case 2:
                                     cout<<"you get away, than are found and put in jail for arson";
                                     break;
                                case 3:
                                     cout<<"You die WOOT"
                                     break;
                                     }
                                }
                    break;
               case 2:
                    cout<<"You don't think this is a good idea.. \n";
                    cout<<"Zzzzz Zzzzzz \n";
                    cout<<"Your back is killing you do you go to the hospital? \n";
                    cout<<"1) Yes \n";
                    cout<<"2) No \n";
                    cin>> input;
                    switch ( input ) {
                           case 1:
                                cout<<"The hospital charges you $50,000 \n";
                                break;
                           case 2:
                                cout<<"Your back make you lose consentration and you fall in a manhole and die!! \n";
                                cout<<"HAHAHAHAHAHA";
                                break;
                           default:
                                   cout<<"ERROR bad choise bye";
                                   break;
                                   }
               case 3:
                    cout<<"Ppl really vote for you so you have to make a platform (statment) \n";
                    cout<<"1) i want candy \n";
                    cout<<"2) Guns for all \n";
                    cout<<"3) I decline! \n";
                    cin>> input;
                    switch ( input ) {
                           case 1:
                                cout<<"You get fired";
                                break;
                           case 2:
                                cout<<"you become the next president and get assasinated";
                                break;
                           case 3:
                                cout<<"Ppl are disipointed in you";
                                break;
                           default:
    
                                   cout<<"ERROR bad choise bye";
                                   break;
                                   }
               }
        cout<<"more? \n";
        cout<<"1) yes \n";
        cout<<" 2) no";
        cin>> a;
        switch ( a ) {
               case 1:
                    break;
               case 2:
                    int x = 1000000;
                    break;
                    }
                    }
        cin.get();
    }


  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    i went thru your program, none of your error are serious,
    they are mostly misplaced or missing ';' in visual studio, just
    read the error and double click it and it will take you to the
    line with the error, and just notice what you did wrong and fix it.

    oh btw, after a if / else / if else / while / for / switch and serveral
    other things you dont need a semi colon after the partheses, just
    the brackets { } .

    Code:
    else if ( temp > 99 ),( temp < 200 ); {
                         cout<<"The potato will be semi cooked \n";
                         }
    should look like this

    Code:
    else if ( temp > 99 &&  temp < 200 )
     {
                cout<<"The potato will be semi cooked \n";
      }
    This is your finalized code with a little better indentations, well in my opinion, with the changes made, i recommend you go thru the code and correct the stuff yourself, but if your still having problems here ya go :

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main () 
    {
        int a,input,temp;
        int x = 1;
        
        while ( x != 1000000 ) 
    	{
    	    cout<<"This is my game !! \n";
    	    cout<<"Ok you have a potato. WOOT! What will you do with it? \n";
    	    cout<<"1) cook the potato \n";
    	    cout<<"2) Use the potato as a pilow and take a nap \n";
    	    cout<<"3) Try to become president? \n";
    	    cin>> input;
    	    switch ( input ) 
    		{
               case 1:
                    cout<<"For how long? /n";
                    cin>> temp;
                    if ( temp < 100 ) 
    				{
                         cout<<"potato is stall \n";
                    }
    			    else if ( temp > 99 && temp < 200 ) 
    				{
                         cout<<"The potato will be semi cooked \n";
                    }
                    else if ( temp > 199 && temp < 300 ) 
    				{
                         cout<<"the potato is cooked well \n";
                    }
                    else if ( temp > 299  && temp < 500 ) {
                         cout<<"the potato was bernt \n";
                         }
                    else if ( temp > 499 ) 
    				{
                         cout<<"your house is on fire!! \n" <<"1) call 911 \n" <<"2) leave. \n" <<"3) stay in bulding";
                         cin >> input;
                         switch ( input ) 
    	         {
                                case 1:
                                     cout<<"Thay save your house steal you good stuff and charg you money for it!?!? \n";
                                     break;
                                case 2:
                                     cout<<"you get away, than are found and put in jail for arson";
                                     break;
                                case 3:
                                     cout<<"You die WOOT";
                                     break;
                           }
    				}
                    break;
               case 2:
                    cout<<"You don't think this is a good idea.. \n";
                    cout<<"Zzzzz Zzzzzz \n";
                    cout<<"Your back is killing you do you go to the hospital? \n";
                    cout<<"1) Yes \n";
                    cout<<"2) No \n";
                    cin>> input;
                    switch ( input ) 
    				{
                           case 1:
                                cout<<"The hospital charges you $50,000 \n";
                                break;
                           case 2:
                                cout<<"Your back make you lose consentration and you fall in a manhole and die!! \n";
                                cout<<"HAHAHAHAHAHA";
                                break;
                           default:
                                cout<<"ERROR bad choise bye";
                                break;
    				}
               case 3:
                    cout<<"Ppl really vote for you so you have to make a platform (statment) \n";
                    cout<<"1) i want candy \n";
                    cout<<"2) Guns for all \n";
                    cout<<"3) I decline! \n";
                    cin>> input;
                    switch ( input ) 
    				{
                           case 1:
                                cout<<"You get fired";
                                break;
                           case 2:
                                cout<<"you become the next president and get assasinated";
                                break;
                           case 3:
                                cout<<"Ppl are disipointed in you";
                                break;
                           default:
                                cout<<"ERROR bad choise bye";
                                break;
    				}
    		}
    		cout<<"more? \n";
    		cout<<"1) yes \n";
    		cout<<" 2) no";
    		cin>> a;
    		switch ( a ) 
    		{
               case 1:
                    break;
               case 2:
                    int x = 1000000;
                    break;
    		}
    	}
        cin.get();
    }
    Last edited by ILoveVectors; 06-14-2005 at 07:02 PM.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    47
    thanx for your help ya thay were small thing but i was doing it quickly

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    47

    Post

    Ok now i wont let me end it at the end the while dosnt stop can anyone tell me why?
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main () {
        int a,input,temp;
        int x = 0;
        
        while ( x != 1 ) {
        cout<<"This is my game !! \n";
        cout<<"Ok you have a potato. WOOT! What will you do with it? \n";
        cout<<"1) cook the potato \n";
        cout<<"2) Use the potato as a pilow and take a nap \n";
        cout<<"3) Try to become president? \n";
        cin>> input;
        switch ( input ) {
               case 1:
                    cout<<"At what temp for 1 hour \n";
                    cin>> temp;
                    if ( temp < 100 )
                    {
                         cout<<"potato is stall \n";
                         }
                    else if ( temp > 99 && temp < 200 )
                    {
                         cout<<"The potato will be semi cooked \n";
                         }
                    else if ( temp > 199 && temp < 300 )
                    {
                         cout<<"the potato is cooked well \n";
                         }
                    else if ( temp > 299 && temp < 500 )
                    {
                         cout<<"the potato was bernt \n";
                         }
                    else if ( temp > 499 )
                    {
                         cout<<"your house is on fire!! \n" <<"1) call 911 \n" <<"2) leave. \n" <<"3) stay in bulding \n";
                         cin>> input;
                         switch ( input ) {
                                case 1:
                                     cout<<"Thay save your house steal you good stuff and charg you money for it!?!? \n";
                                     break;
                                case 2:
                                     cout<<"you get away, than are found and put in jail for arson \n";
                                     break;
                                case 3:
                                     cout<<"You die WOOT \n";
                                     break;
                                default:
                                        cout<<"error bad choise bye \n";
                                        break;
                                     }
                                }
                    break;
               case 2:
                    cout<<"You don't think this is a good idea.. \n";
                    cout<<"Zzzzz Zzzzzz \n";
                    cout<<"Your back is killing you do you go to the hospital? \n";
                    cout<<"1) Yes \n";
                    cout<<"2) No \n";
                    cin>> input;
                    switch ( input ) {
                           case 1:
                                cout<<"The hospital charges you $50,000 your ........ed!! \n";
                                break;
                           case 2:
                                cout<<"Your back make you lose consentration and you fall in a manhole and die!! \n";
                                cout<<"HAHAHAHAHAHA";
                                break;
                           default:
                                   cout<<"ERROR bad choise bye \n";
                                   break;
                                   }
               case 3:
                    cout<<"Ppl really vote for you so you have to make a platform (statment) \n";
                    cout<<"1) i want candy \n";
                    cout<<"2) Guns for all \n";
                    cout<<"3) I decline! \n";
                    cin>> input;
                    switch ( input ) {
                           case 1:
                                cout<<"You get fired, Killed, and raped by a big black guy named bubba \n";
                                break;
                           case 2:
                                cout<<"you become the next president and get assasinated \n";
                                break;
                           case 3:
                                cout<<"Ppl are disipointed in you \n";
                                break;
                           default:
    
                                   cout<<"ERROR bad choise bye \n";
                                   break;
                                   }
               default:
                       cout<<"error bad choise bye \n";
                       break;
               }
        cout<<"more? \n";
        cout<<"1) yes \n";
        cout<<" 2) no \n";
        cin>> a;
        switch ( a ) {
               case 1:
                    break;
               case 2:
                    int x = 1;
                    break;
                    }
                    }
        cin.get();
    }

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>int x = 1;
    That's your problem. You're declaring a new variable local to the switch statement, and then setting its value to 1. The original variable 'x' is not modified. It should be fairly simple to correct this error yourself (involves a click and 4 backspaces ).

    As an aside, you may wish to consider changing x to 'quit' and changing it from int to bool:
    Code:
    bool quit = false;
    while(quit != true)  //or while(!quit)
    {
       ...
       ...
          case 2:
             quit = true;
             break;
    }
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Banned
    Join Date
    Jun 2005
    Posts
    594
    not sure why its not working in this particular situation, maybe you should try :

    Code:
    bool quit = false;
    
    while( quit == false )
    {
           //Stuff
           if(something)
           {
                  quit = true;
           }
    }
    WHOOPS, looks like someone beat me.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    47
    i got it to work by not just using 1,2,3 as the chouses all the time this got out all the buggs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 11:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2003, 12:55 AM

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