basic code not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scrip99
    New Member
    • Jul 2007
    • 7

    basic code not working

    int main()
    {
    int number=rand()%1 00; // rand undecl/?
    int
    guess=-1;
    int trycount=0;
    while(guess!=nu mber && trycount<8)

    {
    {cout<<"Please enter a guess: "; // cout undecl/?
    cin>>guess; // cin undecl/?

    if(guess<number )
    cout<<"Too low"<<endl; //endl undecl/?

    if(guess>number )
    cout<<"Too high"<<endl;

    trycount++;
    }
    if(guess==numbe r)
    {
    cout<<"You guessed the"
    "number";
    }
    else
    {
    cout<<"Sorry, the number was:"
    <<number;
    }
    return 0;
    } // expected `}' at end input/?


    here is what the compiler is saying is wrong.the // is just
    comments from the compiler... trying to get the basics and get to recognize them quickly...thank s for the help..
  • ravenspoint
    New Member
    • Jul 2007
    • 111

    #2
    Add the following line at the top of your code:

    #include <iostream>

    Comment

    • scrip99
      New Member
      • Jul 2007
      • 7

      #3
      Originally posted by ravenspoint
      Add the following line at the top of your code:

      #include <iostream>
      yea but still coming back with same errors.

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by scrip99
        yea but still coming back with same errors.
        What header files you have included in your code?
        If u have included iostream have used the statement using namespace std;

        I think u have missed the inclusion of stdlib.h which is required for rand.


        Raghuram

        Comment

        • scrip99
          New Member
          • Jul 2007
          • 7

          #5
          line 8 while (guess! etc

          says expexted unqualified id before "while"

          what is it ?????

          Comment

          • gpraghuram
            Recognized Expert Top Contributor
            • Mar 2007
            • 1275

            #6
            Originally posted by scrip99
            line 8 while (guess! etc

            says expexted unqualified id before "while"

            what is it ?????
            Can u post ur full code with tags so that it is easier for us to understand the code.
            Also add a comment in the lines where u are getting the error.

            Raghuram

            Comment

            Working...