Thread: whats wrong with this

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    Question whats wrong with this

    i made this kind of for a friend to see if he would get intp programing to but it dont work and i dont know whats wrong...

    Code:
    using namespace std;
    		
    int main()                            
    {
      int game;
      int halo;
    
      cout<<"Please input your game to be rated: n\ 1 for halo 2 for CS 3 for CoD \n";    
      cin>> game;                         
      cin.ignore();                     
      if ( game == 1 ) {                  
         cout<<"please enter kills in halo:\n";
         cin>> halo;
         if ( halo <= 1 ) {
              cout<<"god damn you suck!!!\n";
         else if ( halo <= 10 ) {
              cout<<"new arent you!?\n";
         else if ( halo >= 11 ) {
              cout<<"getting good.\n";
         else if ( halo > 23 ) {
              cout<<"lets play i need a good player! \n";
         else if ( halo => 55 ) {
              cout<<"CAMPER!!! stop camping!! \n";
         cin.get()
         }
              
      if (game == 2 ) {
         cout<<"input kills in cs: \n";
         cin>> cs;
         if ( cs <= 1 ) { 
              cout<<" newbie. \n";
         if ( cs >= 8 ) {
              cout<<"getting better! \n"; 
         if ( cs >= 15 ) {
              cout<<"id play with you but i would win. \n";
         if ( cs >= 25 ) {
              cout<<"could be cheating at this point but not sure how... \n";
         if ( cs >= 40 ) {
              cout<<"total hacker! stop killing bots! there people too. \n";
         cin.get()
         }
         
      if ( game == 3 ) {
           cout<<"please input nuber of kills: \n";
           cin>> cod
         if ( cod <= 2 ) {
              cout<<"try shooting in the other direction. \n";
         if ( cod >= 10 ) {
              cout<<"not bad \n";
         if ( cod >= 20 ) {
              cout<<"sharp shot. \n";
         if ( cod >= 30 ) {
              cout<<"war machine!! \n";
         if ( cod >= 40 ) {
              cout<<"hitler himself. \n";
         if ( cod >= 70 ) {
              cout<<"somehow you are cheating or playing with noobs \n";
         cin.get()
         }
    
    }
    thx anything will help
    i think i overused the if statement lol
    i also think my blocks arent seperated correctly.

  2. #2
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91
    use switch cases, there much easier
    Code:
    int main()
    {
      int input;
      
      cout<<"1. halo\n";
      cout<<"2. CS\n";
      cout<<"3. COD\n";
      cout<<"Selection: ";
      cin>> input;
      switch ( input ) {
      case 1:            
        halo();
        break;
      case 2:            
        cs();
        break;
      case 3:            
        cod();
        break;
      default:            
        cout<<"Error\n";
        break;
      }
      cin.get();
    }
    then just define the halo(); cs(); cod();

    n scribbler is right
    Last edited by digdug4life; 02-13-2005 at 06:10 PM.
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  3. #3
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    One quick glance and I see that cs and cod are never defined. Also your if() statements all have opening brackets, but most of them have no closing brackets.

    Also, the logic you have laid out behind the if statements may produce wierd results...for example, a high mark will fire every if() statement up the tree.
    Last edited by Scribbler; 02-13-2005 at 06:11 PM.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    What is COD? Errrmmmmm....... CS is nick named camper strike camping on halo won't get you very far.
    My computer is awesome.

  5. #5
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91
    Quote Originally Posted by cerin
    camping on halo won't get you very far.
    unless its only 2 ppl, then it might help a little
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by cerin
    What is COD? Errrmmmmm....... CS is nick named camper strike camping on halo won't get you very far.
    CoD = Call of Duty (perhaps?)
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    Quote Originally Posted by DeathDealer's FIXED code
    Code:
    #include <iostream.h>
            
    void main()
    {
        int game, halo, cs, cod;
    
    error:
        cout<<"Please input your game to be rated: \n 1 for halo 2 for CS 3 for CoD \n";
        cin>> game;
        switch (game) {
        case 1:
            cout<<"please enter kills in halo:\n";
            cin>> halo;
            if ( halo <= 1 ) {
                cout<<"god damn you suck!!!\n";
            }
            else if ( halo <= 10 ) {
                cout<<"new arent you!?\n";
            }
            else if ( halo >= 11 ) {
                cout<<"getting good.\n";
            }
            else if ( halo > 23 ) {
                cout<<"lets play i need a good player! \n";
            }
            else if ( halo >= 55 ) {
                cout<<"CAMPER!!! stop camping!! \n";
            }
            cin.get();
            break;
        case 2:
            cout<<"input kills in cs: \n";
            cin>> cs;
            if ( cs <= 1 ) {
                cout<<" newbie. \n";
            }
            else if ( cs >= 8 ) {
                cout<<"getting better! \n";
            }
            else if ( cs >= 15 ) {
                cout<<"i'd play with you but i would win. \n";
            }
            else if ( cs >= 25 ) {
                cout<<"could be cheating at this point but not sure how... \n";
            }
            else if ( cs >= 40 ) {
                cout<<"total hacker! stop killing bots! they're people too. \n";
            }
            cin.get();
            break;
        case 3:
            cout<<"please input number of kills: \n";
            cin>> cod;
            if ( cod <= 2 ) {
                cout<<"try shooting in the other direction. \n";
            }
            else if ( cod >= 10 ) {
                cout<<"not bad \n";
            }
            else if ( cod >= 20 ) {
                cout<<"sharp shot. \n";
            }
            else if ( cod >= 30 ) {
                cout<<"war machine!! \n";
            }
            else if ( cod >= 40 ) {
                cout<<"hitler himself. \n";
            }
            else if ( cod >= 70 ) {
                cout<<"somehow you are cheating or playing with noobs \n";
            }
            cin.get();
            break;
        default:
            cout<<"\nPlease enter a number between 1 and 3.";
            goto error;
         }
    }
    1. You didn't include iostream. Fatal error.
    2. You defined main() as an integer and didn't return a value.
    3. You had invalid escape sequences. (n\)
    4. You had invalid operators. (=>)
    5. You were missing semicolons all over the place
    6. None of the if statements were closed.
    7. As pointed out previously, you didn't define all the variables.
    8. You were using if instead of else if. This wouldn't create compiler errors (perhaps warnings, depending on the compiler) but would not work properly once compiled.

    Also, this isn't critical, but you misspelled half the words in your cout statements.

    Hope this helps.
    Last edited by suzumebachi; 02-14-2005 at 01:14 PM.

  8. #8
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    As an aside to this topic, I feel the need to mention something about Suzumebachi's fix. His solution will work but there is one flaw, the use of goto when a simple loop will do the same thing.

    So, here is a general rule for using goto:
    Don't ever use it.

  9. #9
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Not only should you avoid the use of goto, but void main is also incorrect. Use int main and return a value. Try something like this:
    Code:
    int main()
    {
       int game, halo, cs, cod;
       game = 0;
       while((game > 3) || (game < 1))
       {
        cout << "Please input your game to be rated: \n 1 for halo 2 for CS 3 for CoD \n";
        cin >> game;
       }
       //do the switch thing
       return 0;
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >His solution will work but there is one flaw
    Actually there's numerous flaws. For example, it will never hit these elses:
    Code:
            else if ( halo > 23 ) {
                cout<<"lets play i need a good player! \n";
            }
            else if ( halo >= 55 ) {
                cout<<"CAMPER!!! stop camping!! \n";
            }

  11. #11
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    I don't understand why everyone hates goto so much (maybe it's because I'm used to QBasic and batch files?). And I also don't understand what's wrong with void main() for a simple program.

    As for the elses, I pretty much left them the same and fixed whatever operators he typo'd and closed whatever brackets he left open.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >what's wrong with void main() for a simple program.
    Quick, someone hide Salem.

  13. #13
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    o.O ??????

  14. #14
    Registered User
    Join Date
    Feb 2005
    Posts
    44
    void main is not alright, it doesn't matter how simple the program.

    void main() is not portable code because only some compilers will "fix" this for you.

    Notice the word "fix"

  15. #15
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    ok... so it's a portability issue. but what about the goto?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM