Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ declaration error
#11
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(void)
{
int upperBound;
int lowerBound;
int range;
int guess;
int playersRespond;

srand(time(NULL));

cout << "Upper Bound?\n";
cin >> upperBound;

cout << "Lower Bound?\n";
cin >> lowerBound;

if(upperBound < lowerBound)
{
    cout << "Improper ranges.\n";
    return 0;
  }

cout << "Enter 1 if the number I guess is too low.\n";
cout << "Enter 2 if the number I guess is correct.\n";
cout << "Enter 3 if the number I guess is too high.\n";

do {
    guess = lowerBound + (rand() % upperBound);
    cout << "Is your number" << guess << "?" << endl;
    cin >> playersRespond;
    switch(playersRespond)
    {
    case 1:
      lowerBound = guess;
      break;
    case 2:
      cout << "Damn I'm good!" << endl;
      break;
    case 3:
      upperBound = guess;
      break;
    default:
      cout << "Enter 1 if the number I guess is too low.\n";
      cout << "Enter 2 if the number I guess is correct.\n";
      cout << "Enter 3 if the number I guess is too high.\n";
    }
    if(lowerBound == upperBound)
    {
      cout << "You lying cheat! You switched numbers midgame!\n";
      return 0;
    }
  } while (playersRespond != 2);

  return 0;
}
Reply


Messages In This Thread
C++ declaration error - by sky54264 - 2009-09-15, 12:35 PM
C++ declaration error - by Tempus - 2009-09-15, 12:56 PM
C++ declaration error - by Fiel - 2009-09-15, 01:02 PM
C++ declaration error - by sky54264 - 2009-09-15, 01:04 PM
C++ declaration error - by Tempus - 2009-09-15, 02:56 PM
C++ declaration error - by Fiel - 2009-09-15, 08:13 PM
C++ declaration error - by Takebacker - 2009-09-15, 08:35 PM
C++ declaration error - by Russt - 2009-09-15, 08:52 PM
C++ declaration error - by sky54264 - 2009-09-15, 08:56 PM
C++ declaration error - by Russt - 2009-09-15, 09:07 PM
C++ declaration error - by Fiel - 2009-09-15, 09:19 PM
C++ declaration error - by Russt - 2009-09-15, 10:15 PM
C++ declaration error - by sky54264 - 2009-09-15, 11:08 PM
C++ declaration error - by Russt - 2009-09-15, 11:35 PM
C++ declaration error - by Fiel - 2009-09-16, 09:30 AM
C++ declaration error - by sky54264 - 2009-09-16, 07:23 PM
C++ declaration error - by Russt - 2009-09-18, 08:22 PM
C++ declaration error - by Fiel - 2009-09-19, 05:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)