Thread: error with function, help needed quick

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    error with function, help needed quick

    when the following function runs, it goes straight through without stopping. it also prints out what isn't needed, help please.

    game::gamble()
    {
    char guess;

    cout<<"Winning a gamble wins 5 credits\n";
    gambleval = (rand () % 10) + 1; //generates random number for gamble function
    cout<<" "<<gambleval<<endl;

    cout<<"Higher or lower? correct guess wins.(H for high, l for low)\n";
    cin>>guess;

    if (guess == 'h')
    {
    cout<<"You have guessed higher\n"; //tells player what they guessed
    }
    else
    {
    cout<<"You have guessed lower\n";
    }

    gambleval2 = (rand () % 10) + 1; //generates second random number for gamble function

    if (gambleval2 >= gambleval && (guess == 'h'))
    {
    {
    cout<<"You guessed correct\n"; //if the second number is greater than the first, then it works this out and
    credadd =5; //tells the user they guessed correctly or not
    }
    }
    else
    {
    cout<<"You guessed wrong\n"; //tells the user they guessed wrong in the circumstances
    }

    if (gambleval >= gambleval2 && (guess == 'l'))
    {
    {
    cout<<"You guessed right\n"; //if the second number was smaller than the first then this works it out and
    credadd = 5; //tells the user they guessed correctly
    }
    }
    else
    {
    cout<<"You guessed wrong\n"; //tells the user they guessed wrong under the circumstances
    }
    addcredit(); //calls the update credit function to update the amount of credits in case the player wins
    }

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Give a more detailed explanation as to what you mean "isnt needed". Also, look up the use of code tags you have previous posts also not using them.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    84
    well for example when it generates a number and then asks for the user to guess higher or low, then it will print out if the user has won or lost without them even entering a guess.

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    are u entering capitals? post the cpp file im at school and it takes too long to make a new one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM