beginning do while loopo

Just started a beginners class and can't get my do while loop to work. Can anyone help me with this. The rest of the program works how I expected it to work.
#include <iostream>
using namespace std;

int main ()

{
int accountBalance;
int ans;
float balance;
float balanceOverThousand;
float interest = 0.015;
float extraInterest = 0.01;
float firstThousand;
char doAgain;

do {
cout << "Please enter your account balance: " <<endl;
cin >> accountBalance;


if (accountBalance <=10)
{
cout << "Interest Due: " << (accountBalance * interest) <<endl;
cout << "Total Due: " << (accountBalance) +(accountBalance * interest) << endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
else if ((accountBalance >10)&&(accountBalance <=98))
{
balance = (accountBalance) + (accountBalance * interest);
cout << "Interest Due: " <<accountBalance * 0.015 <<endl;
cout << "Total Due: " <<balance << endl;
cout << "Min Due: " << 10 << endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;

}
else if ((accountBalance >=99) && (accountBalance <=1000))
{
balance = (accountBalance) + (accountBalance * interest);
cout << "Interest Due: " << accountBalance * interest <<endl;
cout << "Total Due: " << balance <<endl;
cout << "Minimum Payment Due: " << balance * 0.10 <<endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
else if (accountBalance >1000)
{
firstThousand =(1000);
balanceOverThousand = ((((accountBalance-1000) * extraInterest))+ ((firstThousand)*interest));
cout << "Interest Due: " << balanceOverThousand <<endl;
cout << "Total Due: " << (balanceOverThousand + accountBalance) <<endl;
cout << "Minimum Payment Due: " << (balanceOverThousand + accountBalance) * 0.10;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
}while (doAgain = 'y' || doAgain = 'Y');

return 0;
}



= assignment
== comparison
closed account (48T7M4Gy)
@cire says:
But, hey.. keep talking out of your ass and filling the forums with misinformation and novice code while pretending you're an expert. I'm sure you're impressing yourself.


This sort of disgraceful language, exaggeration and bullying will not be tolerated Cire. Stop it and apologise.
.
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 accountBalance;
int ans;
float balance;
float balanceOverThousand;
float interest = 0.015;
float extraInterest = 0.01;
float firstThousand;
char doAgain;

do {
cout << "Please enter your account balance: " <<endl;
cin >> accountBalance;


if (accountBalance <=10)
{
cout << "Interest Due: " << (accountBalance * interest) <<endl;
cout << "Total Due: " << (accountBalance) +(accountBalance * interest) << endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
else if ((accountBalance >10)&&(accountBalance <=98))
{
balance = (accountBalance) + (accountBalance * interest);
cout << "Interest Due: " <<accountBalance * 0.015 <<endl;
cout << "Total Due: " <<balance << endl;
cout << "Min Due: " << 10 << endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;

}
else if ((accountBalance >=99) && (accountBalance <=1000))
{
balance = (accountBalance) + (accountBalance * interest);
cout << "Interest Due: " << accountBalance * interest <<endl;
cout << "Total Due: " << balance <<endl;
cout << "Minimum Payment Due: " << balance * 0.10 <<endl;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
else if (accountBalance >1000)
{
firstThousand =(1000);
balanceOverThousand = ((((accountBalance-1000) * extraInterest))+ ((firstThousand)*interest));
cout << "Interest Due: " << balanceOverThousand <<endl;
cout << "Total Due: " << (balanceOverThousand + accountBalance) <<endl;
cout << "Minimum Payment Due: " << (balanceOverThousand + accountBalance) * 0.10;
cout << "Would you like to enter another amount? Enter Y for yes or N for no" <<endl;
cin >> doAgain;
}
}while (doAgain = 'y' || doAgain = 'Y');

return 0;
}
do again was never entered it needs an lvalue, your assigning it with one equal sign
Last edited on
I think both ne555 and rezy3312 did not address the problem clearly enough.

When you compare something with something, don't use assignment operators (=). Use equal comparison operators (==) instead.

So :
while (doAgain = 'y' || doAgain = 'Y');

==>
while (doAgain == 'y' || doAgain == 'Y');
Does that help? :)
Topic archived. No new replies allowed.