I need your help ...pls

Re my program below, I am having difficulty to:
i) ask user if he wants to play again or not after every time he guesses right.
ii) code a counter that controls and update loser how many tries he has left.

I have somewhat code something close to that but mine only worked out per run. I do not want that ... i need it to run until all three sessions are reached

Appreciate your help this!


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
39
40
41
42
43
44
45
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

int main ()
{
char ok = 'y';
char quit = 'q';
int RNbr;
int input;
char responds;

cout <<"Press 'y' to continue OR 'q' to quit: ";
cin >> responds;

if (responds == 'q'){
	return 1;
}
if (responds != 'q'){
	cout << "Input an integer between 1 - 6 inclusive: ";
	cin >> input;
}

srand(time(0));	
RNbr = rand()%6 + 1;

if (input == RNbr){
cout << "You win! ";
}

if (input != RNbr){
   cout << "Incorrect!. Correct number is: " << RNbr << endl;
  }
  int count = 0;
  for (count =0; count <3; count++) {  
  		cout << "you have: " << count << "tries left!" << endl;
  }
  	

	return 0;
}
Hi Tavalya

I would do this in such a way where you have all in for loop

I think your problem is on line 24 - you ask user to input number but only once, whereas this line should be repeated 3 times (as far as I understand your code)

same for test if the number entered is correct, all should be inside the loop.

What you do in line 38-40 is to create a loop that loops over 3 times, but only 1 entry was provided.

Think like compiler, you are going from top to bottom.
So first you set your variables,
then question do you want to continue or quit (this could be while loop == true)
then user input number (once only as there is NO loop there) and number is check if is true or false.
then Loop kicks in and display 3 messages, where it only have informations about 1st.


Hi, Tavalya,

I'm afraid, if you post twice on the same topic
http://www.cplusplus.com/forum/beginner/212525/
you can easily get into a mess of inconsistent answers.

Please, avoid that, it cause people to read your post twice instead of answering other requests.
Thanks
Thank you xxvms for the help and hint. I am now working a while loop which stop when == false.
Hi Enoizat,
you are totally correct and I agree with you ... thank you for pointing me in the right path

Cheers :)
Topic archived. No new replies allowed.