Linked Lists Help
May 23, 2016 at 4:10am UTC
How do I modify this program to track the numbers guessed by the user using a linked list. So basically, i need to keep track if someone already guesses a number and then output if the user did.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(0));
int number = rand()%100+1;
int guess;
cout << "Im thinking of a number between 1-100. Try to guess what it is: " ;
cin >> guess;
while (guess!=number)
{
if (guess>number)
{
cout << "That's too high, guess again: " ;
cin >> guess;
}
if (guess<number)
{
cout << "That's too low, guess again: " ;
cin >> guess;
}
}
if (guess==number)
{
cout << "That's right! It's " << number << endl;
}
return 0;
}
May 23, 2016 at 6:58am UTC
If you must supply your own linked list type, then the first step is probably designing a simple linked list interface separate from this code.
Topic archived. No new replies allowed.