Thread: prog wont work

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    prog wont work

    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    
    using namespace std;
    
    int main();
    {
        int gok;
        int randgetal;
        cout<<"Guess the number i have in mind\n";
        srand((unsigned)time(0));
        randgetal = rand()
        cin >> gok;
        cin.ignore();
        if (gok > randgetal);
           {
                cout<<"Lower!\n";
                }
        if (gok < randgetal);
           {
                cout<<"Higher!\n";
                }
        if (gok == randgetal);
           {
                cout<<"well done\n";
                }
        else ()
             {
                 return main();
                 }
    }
    the error messages are
    8 expected unqualified-id before '{' token
    8 expected `,' or `;' before '{' token


    im new to this and i really cant see why it wont work, any advice would be greatly appreciated

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    int main();
    defines your main function to be ";" -- that is, the empty statement -- and then you have a bunch of stuff in braces that doesn't mean anything.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    16
    Not only that. After else you should remove '()', after the conditions on your if statements remove ';', and after randgetal = rand() insert an ';'.
    Now it will compile but you have no chance on guessing the number, because the number changes at every step of the recursion, since you initialize the seed at each step with current time.

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    thanks for the help, il try and go fix it ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  5. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM