#include <iostream>
#include <string>
#include <cstdlib> // cstdlib for rand() function
usingnamespace std;
using std::string;
int MikeFunction () // Defining function to be called if name is mike
{
int num1,num2,num3;
int random = (rand()%10)+1;
cout << " Great so your name's mike\n\n Let's play a guessing game.\n\n I'm thinking of a number between 1 and 10\n\n";
cout << " I will give you 3 attempts to guess this number\n\n";
cout << " \n Please enter the first number - " ;
cin >> num1;
cout << " \n And the next - ";
cin >> num2;
cout << " \n And the final number please - ";
cin >> num3;
cout << " \n Thanks, i was thinking of " << random << endl;
if (num1== random)
cout << "\nCONGRATS... You got it!";
if (num2== random)
cout << "\nCONGRATS... You got it!";
if (num3== random)
cout << "\nCONGRATS...You got it!";
else
cout << "\n Better luck next time!";
return 0;
}
Right, so this function only gets called if the users name is put in as mike.
It then goes on to ask for 3 numbers from the user between 1 and 10, then compares it to what rand() has generated, and either congratulates the user or says better luck next time depending if the users input matches.
This all compiles fine, the only problem is that each and every time im run this program, it generates the same number...'2'.
I cant think why this would be or how to sort it out...