Check This Out

Write your question here.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <cstdlib>  // For rand and srand
#include <ctime>	// For the time function
using namespace std;

int main()
{
	
	srand(time(0)); // Confused about this
	int Guess1;
	int RanNum; 
	int NumberCorrect = 0, NumberIncorrect = 0;
	
	
	cout << "Welcome to the guessing game! " << endl;
	cout << "Choose Wisely: This is a best of seven game. " << endl;
	
	// Guess Section
	
	do 
	{
		cout << "" << endl;  // Space
		cout << "I am thinking of a number from 1 to 4. " << endl;
		cout << "What is your guess? ";
		cin >> Guess1;
		if (Guess1 > 4 || Guess1 < 1)
		{
			cout << "Error: Please guess a number between 1 and 4. " << endl;
		}
		
		RanNum = rand() % 4 + 1; // Makes RanNum between 1 and 4
		
		
		if (Guess1 != RanNum)
		{
			cout << "" << endl;
			cout << "Sorry! I was thinking of " << RanNum << endl;
			++NumberIncorrect;
			
			
			
			// Hint Section
			if (NumberIncorrect == 2 && RanNum == 2 || RanNum == 4)
			{
				cout << "" << endl;
				cout << "Here is a hint.  The number is even. " << endl;		}
			
			
			
			if (NumberIncorrect == 2 && RanNum == 1 || RanNum == 3)
			{
				cout << "" << endl;
				cout << "Here is a hint.  The number is odd. " << endl;		    }
		}
		
		
		if (Guess1 == RanNum)
		{
			cout << "" << endl;
			cout << "Correct! I was thinking of " << RanNum << endl;
			++NumberCorrect;
		}
		
		
		
	// Win or Lose Section	
	} while(NumberCorrect != 4 && NumberIncorrect != 4);
	
	cout << "Correct - " << NumberCorrect << "\t Incorrect - " << NumberIncorrect << endl;
	
	{
		if (NumberCorrect >= 4) { cout << "You Win!" ;  // Not sure why the program didn't build when I wrote if (NumberCorrect == 4)
			cout << "" << endl;}    
		
		if (NumberIncorrect >= 4) { cout << "You Lose!" ;  // Same as above with (NumberIncorrect == 4)
			cout << "" << endl;}   // Greater than worked
		
	}
	
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.