I need help with a do/while loop please

Okay, our instructor gave us two labs at once. I finished the first part, and it works just fine. It does everything it is supposed to do. What I need help with is the do/while loop. I am not sure how to set one up. I will post the lab assignments below so you can see exactly what the parameters are. This lab is due tomorrow.

This is the first lab that works just fine
Write a program which implements a banking system. In your program you should be asking the followings from the user:



A. What type of bank account.

B. Amount of deposit.

C. Duration of deposit.



If bank account is of type 'Checking' an interest rate of 5% per year is given.

If banks account is of type 'Saving' an interest rate of 10% per year is given.



Interest rate are applicable only when the duration equal to or more than one year and deposit amount is more than $ 1,000. For deposit less than one year or for deposit less than $1,000, no interest is paid. You need to calculate the interest amount.



Please make sure you cover all the requirements and test your program for all possible cases. The cases should be:



1.Checking with deposit for less than a year with deposit greater than 1000.
2.Checking with deposit for more than a year and deposit greater than 1000.
3.Saving with deposit for less than a year and deposit amount greater than 1000.
4.Saving with deposit for more than a year deposit amount greater than 1000.
5.All above 4 cases with deposit less than 1000.
6.If the user enters a account type which is not either 'Checking' or 'Saving' exit from the program with an error message.

****this is the second lab.
This lab is based on lab 4. In this you will make your program to work in a loop and do exactly the same thing as the lab. The adding to this would be the program would ask the user



'Do you want to calculate the interest for an account?'

if answer is 'Yes', calculate the interest. Once calculated again ask the user same question and repeat the process.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;

int main()
{

	int duration;
	char c;
	char s;
	double interest;
	double ammount;
	char account;
	
	cout<<"How much would you like to deposit?"<<endl;
	cin>>ammount;
	cout<<"Would you like to open a checking account or a saving account?"<<endl;
	cout<<"Enter C for checking or S for saving."<<endl;
		cin>>account;
	
	if (account=='c'||account=='C')
	{
		interest=ammount*.05;
	}

	else if (account=='s'||account=='S')
	{
		interest=ammount*.1;
	}	
	else 
	{
		cout<<"Wrong type of account! Try again!"<<endl;
cin.get();
cin.get();
return 0;
	}



	
	;{
		int duration;
		
	cout<<"How many months would you like to open your account for?"<<endl;
	cin>>duration
		;if (duration>=12&&ammount>=1000)
	
			cout<<"Your balance is "<<ammount+interest<<endl;
	
		else if (duration<12||ammount<1000)
	
			cout<<"Your balance is "<<ammount<<endl;
	
	
		
	;cin.get();
	cin.get();

	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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;

int main ()
{
	int duration;  
	double interest;
	double amount;
	char account;
	char answer;  //variable to control the do while loop

	do
	{
	cout << "How much will you like to deposit? >> ";
	cin >> amount;
	cout << endl;
	cout << "What's your preferred account type"
		 << "\nEnter S for saving or C for checking >> ";
	cin >> account;
	cout << endl;

	//You can still continue with your if else statement 
	//if you haven't done switch structure yet.
	switch (account)
	{
	case 'c':
	case 'C':
		interest =  amount  * 0.05;
		break;
	case 's':
	case 'S':
		interest = amount * 0.10;
		break;
	default:
		cout << "\nInvalid account type. Try again!" << endl;
		return 0;
	}

	cout << "Enter the time duration in months >> ";
	cin >> duration;
	cout << endl;

	if (duration >= 12 && amount >= 1000)
		cout << "Amount Due = $" << amount + interest 
		     << endl;
	else
		cout << "Amount Due = $" << amount << endl;

	cout << "\n\nDo you wish to perform another operation"
		 << "\nEnter y for yes or any key to exit >> ";
	cin >> answer;
	cout << endl;
	}
	while (answer == 'y' || answer == 'Y');

	cout << "\nProgram terminating..... bye !!!" << endl;

	return 0;
}// I don't think I need to document this program, what do you think?



Topic archived. No new replies allowed.