So I am trying to compile this program, and I know that the only problem with my code has to do with the "while" section of the do while loop, either that or something to do with those variables. I declared the variable "repeat" as a char, and prompted the user to enter y or n, and had that be the input to the variable "repeat". The compiler thinks they are undeclared identifiers though. Any suggestions? Thanks.

#include <iostream>
using namespace std;

double hatsize (int height, int weight);
double jacketsize (int height, int weight, int age);
double waistsize (int weight, int age);

int main ()
	int height, weight, age;
	double hat, jacket, waist;
	char repeat;

		cout << "Please enter your height in inches "; 
		cout << "(rounded to the nearest inch) and press enter (0 to quit).";
		cin >> height;
		cout << "Please enter your weight in pounds";
		cout << " (rounded to the nearest pound) and press enter.";
		cin >> weight;
		cout << "Please enter your age in years";
		cout << " (rounded to the nearest year) and press enter.";
		cin >> age;

		hat = hatsize(height, weight);
		jacket = jacketsize(height, weight, age);
		waist = waistsize(weight, age);

		cout << "Your hat size is " << hat<< endl;
		cout << "Your jacket size is " << jacket << " inches." <<endl;
		cout << "Your waist size is " << waist << " inches." << endl;
		cout << endl;
		cout << "Would you like to get fitted again? (y/n)";
		cin >> repeat;
	}while ((repeat = y) || (repeat = Y));

	return 0;

double hatsize (int height, int weight)
	return 2.9*(weight/height);

double jacketsize (int height, int weight, int age)
	double x = (height*weight)/288;
	int y = (age - 30)/10;
	return (x + ((1/8)*y));

double waistsize (int weight, int age)
	double x = weight/5.7;
	int y =(age-28)/2;
	return (x + .1*y);
while ((repeat = y) || (repeat = Y));

You are attempting to assign the variables 'y' and 'Y' to the variable 'repeat' rather than comparing to the characters. There are two issues:

1.) You need to use the equality operator not the assignment operator.

2.) To make the compiler consider 'y' and 'Y' as chars not variable names you must enclose them in single quotes ( 'Y' ). Make sure you don't use double quotes ( "Y" )., that makes it interpret them as strings.

Thanks a lot!
This article has been dead for over six months. Start a new discussion instead.