So i want my program to loop while the user continues to say yes and i figured that my code below would work but for some reason it says that y is an undeclared identifier.

# include <iostream> 
# include <fstream> 
# include <cstdlib>
# include <string>
# include <cmath>

using namespace std;
 
int main () 
{

	
	double balance, interest, minpayment;
	
	int month(0);

	char yesorno;

	cout << " Enter your account balance: " << endl;
	cin >> balance;
			

	do
	{

			if (balance <= 1000)
			{
				interest = balance * .015;
				balance = balance * 1.015;
			}	
			else
			{
			
				interest = balance * .01;
				balance = balance * 1.01;

			}
	
	
			if (balance <= 10)
			{
				minpayment = balance;

			}

			else if (balance * .1 < 10)
			{
				minpayment = 10;

			}

			else
			{
				minpayment = balance * .1;
			}



			month = month++;
		



		
		cout << " Month " << month << endl;
		cout << " Interest is: " << interest << endl;
		cout << " Account balance is: " << balance << endl;
		cout << " Minimum payment is: " << minpayment << endl;
	
		

		cout << " Would you like to see the next months figures?  Y/y or N/n " << endl;
		
		cin >> yesorno;

	}		
		
	
		while (yesorno == y);
			char y;

	
	


	

	
	return(0);

}

Recommended Answers

All 5 Replies

you need to move your declaration of y to be before the do statement on line 23. the reason is that when the compiler hits the while statement it hasn't seen the deceleration for y so it doesn't know what it is. also a easy way to do the while statement would be

while(yesorno == 'Y' || yesorno =='y')

this will make sure that only a Y or a y will continue the code and all other inputs will be treated like a N or n

So from below if I have single quotes around the letter it just looks for the character Y or y in the input?

you need to move your deceleration of y to be before the do statement on line 23. the reason is that when the compiler hits the while statement it hasn't seen the deceleration for y so it doesn't know what it is. also a easy way to do the while statement would be

while(yesorno == 'Y' || yesorno =='y')

this will make sure that only a Y or a y will continue the code and all other inputs will be treated like a N or n

yes the while statement i wrote will check to see if the use entered Y or y. if the user enters either of the toughs the do while loop will continue. all other inputs will stop the loop and end the program.

cool thanks for the help

no problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.