Why doesnt it want me to use getline

why is getline not allowed here and also whey is the else statement not supposed to be and where do i put the break if i want it to exit the loop if they answer correct

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
#include<string>
#include<iostream>
using namespace std;

void game(void);

int SecretNumber = 3;
int Counter = 0;

string Correct = "You guessed my Number!!";
string Incorrect = "You guessed wrong try again";


void game(int guess, string Correct, string Incorrect)
{
	do
	{
		cout << "I'm thinking of a number between 1 and 10 guess till you get it correct";
		getline(cin, guess);
		cin.ignore(999, '\n');
		if (!cin.fail());
		cin.clear();
		cin.ignore(999, '\n');
		cout << "You need to enter a. Try again.";
	}
		while (guess != SecretNumber);
		++Counter && cout << Incorrect << "You have guessed" << Counter << "times";
			
		else 
			cout << Correct;
			break;
}


int main(void)
{
	game();


	cin.ignore(999, '\n'); 
	cout << "Press ENTER to finish...";
	return 0;
}
why is getline not allowed here

Possibly because getline() only works with strings not integers.

also whey is the else statement not supposed to be

An else statement required an if() statement.
Topic archived. No new replies allowed.