Fix Please

This is a discussion on Fix Please within the C++ Programming forums, part of the General Programming Boards category; Okay i can't fix it with the limited knowledge i have... please someone help Code: #include <iostream> using namespace std; ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    25

    Fix Please

    Okay i can't fix it with the limited knowledge i have... please someone help



    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int number;
        cout<<"Wecome to the attempted C++ \n Press enter to continue.";
        cin.get();
        
        cout<<"Choose a number from 1 to 10 and \n you will be rewarded if you guess correctly.";
        cin>> number;
        cin.ignore();
        
        if (number)!(1&&2); { cout<<"Try again!"; 
        }
        
        else if (number<2); {cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";}
        cin.get();
    }

    errors
    E:\Programs\Programing\Programs\Guessing Game.cpp: In function `int main()':
    E:\Programs\Programing\Programs\Guessing Game.cpp:18: error: expected primary-expression before "else"
    E:\Programs\Programing\Programs\Guessing Game.cpp:18: error: expected `;' before "else"

    Execution terminated

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> if (number)!(1&&2);
    This line has a syntactic error and a semantic error. Lookup how to use && in your book/tutorial and pay attention to the difference between the example and your code. Then lookup the syntax for the if /else if statements.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    Daved, that not the error that the compiler found but i fixed what you said,

    what do i do with the "else if" cause i can't understand what i'm missing

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int number;
        cout<<"Wecome to the attempted C++ \n Press enter to continue.";
        cin.get();
        
        cout<<"Choose a number from 1 to 10 and \n you will be rewarded if you guess correctly.";
        cin>> number;
        cin.ignore();
        
        if (number)!(1||2); { cout<<"Try again!"; 
        }
        
        else if(0<number<2); {cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";}
        
        else {cout<<"Between 1 and 10 please"; }
        cin.get();
    }

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    This entire snippet is wrong (not to mention confusing):
    Code:
        if (number)!(1||2); { cout<<"Try again!"; 
        }
        
        else if(0<number<2); {cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";}
        
        else {cout<<"Between 1 and 10 please"; }
    Look up ifs. You are doing them wrong, wrong, wrong, wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    hehe wow you're great, you will be a great parent!

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    I don't know if that's supposed to be a compliment or a sarcastic response...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Code:
    if( condition )
    { // these are optional if only one statement follows.
        dosomething;
    }
    else if( condition )
        dosomething;
    else
        dosomething;

    in your case :

    Code:
    if (number)!(1||2);
    This doesn't conform to the above. Your if condition must be contained in ( )'s. There should NOT be a ';' after the if statement.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    While we're at it, this will only cause readability problems:
    Code:
        else if(0<number<2) {cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";}
    Better version:
    Code:
    else if(0<number<2)
    {
        cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";
    }
    Or:
    Code:
    else if(0<number<2) {
        cout<< "You win ....";
        cin.get(); 
        cout<<"Nothing.";
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    I solved it YES!!!!!!!!!!! Thanks Elysia, can you by anychance add me on msn? (sabatnestor@hotmail.com)

    Try out this sick game.
    I could sell this on the Black market :O :P
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int number;
        cout<<"Wecome to the attempted C++ \n Press enter to continue.";
        cin.get();
        
        cout<<"Choose a number from 1 to 10 and \n you will be rewarded if you guess correctly.";
        cin>> number;
        cin.ignore();
        
        if (!(1||2)) { cout<<"Try again!"; 
        }
        
        else if(number>0 && number<2) {cout<< "You win ....\n...Nothing";}
        
        else {
             cout<<"Between 1 and 10 please"; }
        cin.get();
    }

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    I'm not sure this one is correct:
    if (!(1||2))
    And I'm not sure your logic for the entire if is correct either...
    Should it not be something along the lines of:

    if number < 1 or number > 10 Error
    if number == 1 you win
    Otherwise you lose.

    ?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    if (!(1||2))
    This is always false. Use the equality operator and actually make a comparison with your number.

    if (number>0 && number<2)
    While not as straight forward, it's right. The only number more than zero and less than two is one. It's also lame, because the game cheats. Use random numbers from a generator, Nestor.

  12. #12
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Care to explain a few things?

    What is the condition !(1 || 2) supposed to check? (Or, do you think it is meaningful to write code that will never be executed?)

    How exactly do you know in the final else part that the input was not between 1 and 10? Or is this program annoying on purpose?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  13. #13
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    Okay let me explain to you my logic, when you play a game the better the ods the more you want to play it, that basically it, but you are right, it should be one number only.

    You catch all mistakes :P

  14. #14
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    anon i swear i burst out laughing when i read what you wrote haha "is this program supposed to be annoying" HAHAHAHHAHAHAHA!
    good one

  15. #15
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    Quote Originally Posted by citizen View Post
    if (!(1||2))
    This is always false. Use the equality operator and actually make a comparison with your number.

    if (number>0 && number<2)
    While not as straight forward, it's right. The only number more than zero and less than two is one. It's also lame, because the game cheats. Use random numbers from a generator, Nestor.
    Listem men, i started programing yesterday....well today 1 am, i havn't gotten as far as a random numbers generator:P but if you are bored you can explain how it can be a random number generator if the computer can't think for itself?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. Drag and Drop code (please help me fix)
    By John_L in forum C# Programming
    Replies: 1
    Last Post: 11-17-2007, 05:11 PM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. Help me fix my mess!!!!
    By Starr in forum C++ Programming
    Replies: 35
    Last Post: 02-01-2006, 02:40 PM

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