Advice on knowing what loop to use.

Here is the scenario:
Modify the program to run the whole program as often as the user wants.Specifically run the whole program AT LEAST ONCE for the first set of input values, then ask if the user wants to run the program again. If the says yes run the program again for different values. If the user says no, say " GOODBYE" and terminate the program.Use the most appropriate LOOP construct to repeat getting input, doing calculations and printing until the user says to stop. You can make up how or what you ask the user when finding out if he/she wants to run it again with another set of input values Run the code ONCE giving these input values:
Cost: $50.00 Mark-up percentage: 10% Sales tax rate: 5%
Cost: $250.00 Mark-up percentage: 45% Sales tax rate: 12%
Cost: $25.00 Mark-up percentage: 5% Sales tax rate: 10%
Cost: $100.00 Mark-up percentage: 8% Sales tax rate: 3%

Would it make sense to use the FOR loop? or Do while? Why?
Last edited on
so i would use the do while loop right? Sorry i am really knew to programming.
yes, you would. The key word is AT LEAST ONCE.

Good luck!
ok thank you but now i do not know how to go about this assignment since i have to do the do while loop...this is what i have so far:

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
30
31
32
33
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	cout <<"Rebecca Carolina Katz, lab 6 part b" << endl;
	
	// Variable declarations
	float cost;
	float mark_up_percentage;
	float sales_tax_rate;
	
	do 
	{
		cout <<"Enter Wholesale Cost:" << endl;
		cin >> wholesale_cost;
	}while 
	
	do
	{
		cout <<"Enter Mark-up percentage:" << endl;
		cin >> mark_up_percentage
	}while
	
	do 
	{
		cout <<"Enter sales tax rate:" << endl;
		cin >> sales_tax_rate
	}while 
	
	return 0;
}
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
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cmath>
// using namespace std; // *** avoid

int main()
{
	std::cout <<"Rebecca Carolina Katz, lab 6 part b\n" ; // endl;;

	// Variable declarations
	/* float */ double wholesale_cost ; // cost; // *** favour double as the default floating point type
	/* float */ double mark_up_percentage;
	/* float */ double sales_tax_rate;

	char run_the_program_again ; // *** added 

	do
	{
		std::cout <<"\nEnter Wholesale Cost: " ; // endl;;
		std::cin >> wholesale_cost;

		std::cout <<"Enter Mark-up percentage: " ; // endl;;
		std::cin >> mark_up_percentage;

		std::cout <<"Enter sales tax rate: " ; // endl;;
		std::cin >> sales_tax_rate;

		// perform calculations

		// print result

		// ask if the user wants to run the program again
		std::cout << "\nrun the program again (y/n)? : " ;
		std::cin >> run_the_program_again ;

	} while( run_the_program_again == 'y' || run_the_program_again == 'Y' ) ; // repeat if the user said yes

	std::cout << "\nGOODBYE\n" ;

	// return 0; // *** implicit
}
okay thank you for your reply!
This was the output i got all in the first run not sure how to do an attachment on here:

Enter Wholesale cost: 50.00
Enter mark-up percentage: 0.10
Enter salestax rate: 0.05
run the program again? (y/n): Y


Enter Wholesale cost: 250.00
Enter mark-up percentage: 0.45
Enter salestax rate: 0.12.

Run the program again? (y/n) :Y

how would i do the calculations?
Topic archived. No new replies allowed.