Yes or No loop

Feb 10, 2015 at 8:35pm
In class we are doing a problem where we ask the height in inches, and display the height it feet an inches. Then we have to ask if they would like to enter another height, which is where I am stuck. I have where it asks "Do you want to enter another height (Y/N)" I just dont know how to loop so it will continue the program until the user selects "N"


*edit* I did i do-while loop and it asks the user once more to enter their height, and after that one time it ends the program.






#include <iostream>
using namespace std;

int main()
{
int Feet;
int Inches;
char response;
Inches = 0;
Feet = 0;
char n = 0;
char N = 0;
char Y = 0;
char y = 0;
response = 0;

cout << "Please enter your height in inches ";
cin >> Inches;
cout << endl;

Feet = Inches / 12;
Inches = Inches % 12;

cout << "You are " << Feet << " feet ";
cout << Inches << " inches tall!";
cout << endl;


cout << "Do you want to enter another height (Y/N) ";
cin >> response;

do
{
cout << "Please enter your height in inches ";
cin >> Inches;
cout << endl;
}

while (response == Y || response == y);


}
Last edited on Feb 10, 2015 at 8:43pm
Feb 10, 2015 at 8:49pm
you have to move all of your questions into that do while loop.

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

int main()
{
	int Feet(0);
	int Inches(0);
	char response('y');

	do
	{
		cout << "Please enter your height in inches ";
		cin >> Inches;
		cout << endl;

		Feet = Inches / 12;
		Inches = Inches % 12;

		cout << "You are " << Feet << " feet ";
		cout << Inches << " inches tall!";
		cout << endl;


		cout << "Do you want to enter another height (Y/N) ";
		cin >> response;
	}while (response == 'Y' || response == 'y');  // <- i fixed this too.

	return 0;
}
Last edited on Feb 10, 2015 at 8:54pm
Feb 10, 2015 at 9:01pm
Thank you so much! i understand what im doing a little more now.
Topic archived. No new replies allowed.