im trying to create a simple program that mimics a savings account. I'm getting stuck at the "yes/no" while loops where the program wont go to the "no" part of the program if i type "n". I'm also allowed to assume that the customer won't make a withdraw and deposit in the same month.
/*
jake lemay, block 004
program will mimic a savings account
input: initial deposit, withdraw, balance
output: new balance, interest
processing:
*/
#include<iostream>;
#include<iomanip>;
using namespace std;
int main()
{
int interestRate;
int initialDeposit;
int deposit;
int withdraw;
int balance;
int change;
int months;
char choice;
char y;
char n;
//use for, while, and do while loops each at least once!!!
cout << "what is your yearly interest rate for this account?\n"
<< "please input xx.x% ONLY in the form xx.x, not 0.xxx\n"
<< "an incorrect form will result in an incorrect rate\n"
<< "example:" << " " << "correct: 11.5" << " " << "incorrect: 0.115\n\n"
<< "interest rate: ";
cin >> setprecision(3) >> interestRate;
cout << "what is your initial deposit?: ";
cin >> initialDeposit;
if (initialDeposit < 250)
{
cout << "please deposit at least $250 into your account.\n"
<< "what is your initial deposit?\n\n"
<< "initial deposit: ";
cin >> initialDeposit;
}
for (;balance >= 250;)
{
cout<< "would you like to deposit more money into this account? (y/n): ";
cin >> choice;
while (choice == y);
{
cout << "how much would you like to deposit?: ";
cin >> deposit;
change = deposit;
cout << "you currently have " << balance << " in your account.\n";
}
while (choice == n)
{
cout << "would you like to withdraw money from this account? (y/n): ";
cin >> choice;
if (choice = y)
{
cout << "how much would you like to withdraw?: ";
cin >> withdraw;
if (withdraw <= 0)
{
cout << "you must withdraw more than $1\n"
<< "how much would you like to withdraw?: ";
cin >> withdraw;
}
else
{
change = -withdraw;
if (balance < 250)
{
cout << "your balance cannot fall below $250.\n"
<< "how much would you like to withdraw?: ";
cin >> withdraw;
}
else
{
cout << "you currently have " << balance << " in your account.\n";
}
}
while (choice == n)
{
change = balance;
cout << "you currently have " << balance << " in your account.";
}
for (;months=12;)
{
cout << "would you like to continue your account another year?";
cin >> choice;
{
do
{
cout<< "would you like to deposit more money into this account? (y/n): ";
cin >> choice;
}
while (choice==y);
do
{
cout << "thank you for your service with this bank account. good bye.";
return 0;
}
while (choice==n);
}
}
}
}
You're not checking the inputs against a char. For that, you need to enclose the y and n in single quotes. 'y' and 'n'. Also, this change = -withdraw, will not decrease change by the withdrawal. It assigns change to a minus withdraw. To decrease change, it should be change -= withdraw which means 'change equals change minus the value of withdraw'
ok so i made the changes, but im still stuck at the same place.
/*
jake lemay, block 004
program will mimic a savings account
input: initial deposit, withdraw, balance
output: new balance, interest
processing:
*/
#include<iostream>;
#include<iomanip>;
usingnamespace std;
int main()
{
int interestRate;
int initialDeposit;
int deposit;
int withdraw;
int balance;
int change;
int months;
char choice;
char y;
char n;
//use for, while, and do while loops each at least once!!!
cout << "what is your yearly interest rate for this account?\n"
<< "please input xx.x% ONLY in the form xx.x, not 0.xxx\n"
<< "an incorrect form will result in an incorrect rate\n"
<< "example:" << " " << "correct: 11.5" << " " << "incorrect: 0.115\n\n"
<< "interest rate: ";
cin >> setprecision(3) >> interestRate;
cout << "what is your initial deposit?: ";
cin >> initialDeposit;
if (initialDeposit < 250)
{
cout << "please deposit at least $250 into your account.\n"
<< "what is your initial deposit?\n\n"
<< "initial deposit: ";
cin >> initialDeposit;
}
else
{
balance = initialDeposit + initialDeposit*interestRate/100;
cout << "your balance is " << balance << "\n";
for (;balance >= 250;)
{
cout<< "would you like to deposit more money into this account? (y/n): ";
cin >> choice;
while (choice = 'y');
{
cout << "how much would you like to deposit?: ";
cin >> deposit;
balance = balance+deposit*interestrate/100;
cout << "you currently have " << balance << " in your account.\n";
}
while (choice == 'n')
{
cout << "would you like to withdraw money from this account? (y/n): ";
cin >> choice;
if (choice = 'y')
{
cout << "how much would you like to withdraw?: ";
cin >> withdraw;
if (withdraw <= 0)
{
cout << "you must withdraw more than $1\n"
<< "how much would you like to withdraw?: ";
cin >> withdraw;
}
else
{
balance = balance-withdraw*interestrate/100;
if (balance < 250)
{
cout << "your balance cannot fall below $250.\n"
<< "how much would you like to withdraw?: ";
cin >> withdraw;
}
else
{
cout << "you currently have " << balance << " in your account.\n";
}
}
while (choice == 'n')
{
balance = balance+balance*interestrate/100;
cout << "you currently have " << balance << " in your account.";
}
for (;months=12;)
{
cout << "would you like to continue your account another year?";
cin >> choice;
{
do
{
cout<< "would you like to deposit more money into this account? (y/n): ";
cin >> choice;
}
while (choice=='y');
do
{
cout << "thank you for your service. good bye.";
return 0;
}
while (choice=='n');
}
}
}
}
}
}
}
[code]