ok i got my program to work but i can't figure out how to make it to come out right.
the user can input the numbers 1-10 but when they enter a low or high number a message should come out.
// Give Me a Number
// Demonstrates default function arguments
#include <iostream>
#include <string>
using namespace std;
int askNumber(int high, int low=0 );
int main()
{
int number = askNumber(10,1);
if (10 > number )
cout << "Thanks for entering: " << number << "\n\n";
else
number = askNumber(0);
cout << "Thats invilid to low, pick 1-10 \n\n";
system ("pause");
return 0;
}
int askNumber(int high, int low)
{
int num;
do
{
cout << "Please enter a number" << " (" << low << " - " << high << "): ";
cin >> num;
} while (num > high || num < low);
// Give Me a Number
// Demonstrates default function arguments
#include <iostream>
#include <windows.h> // for srand(GetTickCount());
usingnamespace std;
int askNumber(int high, int low, int computer_num );
int main()
{
srand(GetTickCount());
int low, high, number, picked_number, guesses = 1;
picked_number = 1+rand()%99; // 1 to 100
low = 1;
high = 100;
while (number != picked_number)
{
cout << "Guess #" << guesses << endl;
number = askNumber(high,low, picked_number);
guesses++;
if (number < picked_number) // Update low and high variables
low = number;
if (number > picked_number)
high = number;
};
cout << endl << "You took " << guesses << " guesses, to find my number.."<< endl;
return 0;
}
int askNumber(int high, int low, int computer_num)
{
int num;
do
{
cout << "Please enter a number" << " (" << low << " - " << high << "): ";
cin >> num;
if (num<computer_num && num > low)
cout << "Your guess is to low.." << endl;
if ( num > computer_num && num < high)
cout << "Your guess was to high.." << endl;
if ( num == computer_num)
cout << "Yep.. That's my number.." << endl;
if(num < 0 || num > 100)
cout << "Come on now. We're only using guesses from 0 to 100" << endl;
if(num < low || num > high)
cout << "Please keep an eye on the previous guesses!!" << endl;
} while (num < low || num > high);
return num;
}