0

I am writing a program in which the user enters a number between 1 and 3 (3 meaning that he/she would like to quit) and I am using a switch function within a do-while loop. I am trying to get the program to end the loop when the user enters the number 3. However, my program is only continuing the loop when the user enters 3. Can anyone help me fix this please? Thanks so much!

-Mikaela

Attachments
// Exam 01 Code Created by Mikaela Anderson 06/11/2009 for CET2364 (Calculates price of an item including sales tax for Seminole or Orange County tax rates)
#include <iostream>
using namespace std;

int main()
{
	int userChoice;
	double price;
	double seminoleTaxrate;
	double orangeTaxrate;
	double seminoleTax;
	double orangeTax;
	double seminoleTotal;
	double orangeTotal;
	bool quit;
	do
	{
		do
		{
			cout << "Please select from one of the following: \n";
			cout << "Orange County [1], ";
			cout << "Seminole County [2], ";
			cout << "Quit [3]: ";
			cin >> userChoice;
			if ((userChoice <= 0) || (userChoice >= 4))
			{
				cout << "Incorrect choice. Try again.\n";
			}
		} while ((userChoice <= 0) || (userChoice >= 4));
			
		cout << "\nEnter the price of the item: ";
		cin >> price;

		seminoleTaxrate = .070;
		seminoleTax = price * seminoleTaxrate;
		seminoleTotal = price + seminoleTax;
		orangeTaxrate = .065;
		orangeTax = price * orangeTaxrate;
		orangeTotal = price + orangeTax;

		switch (userChoice)
		{
			case 1:
				cout << "\n     Price: " << price << "\n";
				cout << "     Tax: " << seminoleTax << "\n";
				cout << "     Total: " << seminoleTotal << "\n\n";
				break;
			case 2:
				cout << "\n     Price: " << price << "\n";
				cout << "     Tax: " << orangeTax << "\n";
				cout << "     Total: " << orangeTotal << "\n\n";
				break;
			case 3:
				quit = true;
				break;
			default:
				;
		} 
	} while (quit == false);
	
	return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sloan31
0

Follow the logic flow line by line, you are asking for the user to enter the price for the item after they make the choice between 1,2, or 3 regardless of which choice they made.

The do...while loop involving the switch statement doesn't come into play until after the user has entered a price. So unless they enter a price of 3, this will never exit.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.