i am beginer so i need help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;
int main() {

	int i , y = 1 , n = 0;

	cout << " do you weant continu ? y/n : ";
	cin >> i;

	if (i == 1) {
		
		cout << " it is working oooo" << endl;
		
	}


	system("pause");
	return 0;
}



why it does not works ?

I need a program that will finally asks me "want to try again? y/n ? "
P.s : sorry for my broken English
Last edited on
why it does not works ?

It works exactly how you programmed it =)

If you want it to ask you over and over again until you enter "y" then you'll need a loop - http://www.tutorialspoint.com/cplusplus/cpp_loop_types.htm

Read @MikeyBoys's post.
Last edited on
You ask the user to enter a character 'y' or 'n'. However, you store that value in an integer, not a char, and you then you compare that value to 1, not to 'y'. Why would the user enter a 1, when you've asked them to enter a 'y' or an 'n'?

Also, on line 6, you've defined two variables, y and n, that you never use. Declaring variables with those names does not somehow magically associate them with the characters 'y' and 'n'.

You should have asked this question in the beginners forum.

int i , y = 1 , n = 0;
you have not used the variables y and n, so there is no use of them. Also if you are asking the user for a 'y/n' response, i should be of 'char' type, not 'int' type.

if (i == 1)
should be
if (i == 'y')
now if user inputs 'y', the following block is executed

I need a program that will finally asks me "want to try again? y/n ? "

to do that, you need a loop.
tom221b thenx so much i forgot ' i wrote if ( i == y ) and ofc it was wrong
sorry for my english
thenx all for answers

and it is working well :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() {

	char i , y , n;
	
	cout << " do you weant continu ? y/n : ";
	cin >> i;
	
	cout << i << endl;
	if (i == 'y') {
		
		cout << " it is working oooo" << endl;
		
	}


	system("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.