Problem with multipication code and loop


Hi all I'm new to the CIS field thought it would be a great new career at 40 years old. LOL the first week was great, but wow this second week is crazy with information. Need help with this program, can't seem to get my formula correct. Thanks in advance. Also can't get the second interest rate to add the 1.5%, and can't get the statement to loop again to ask for another input amount. This is what I have so far any suggestions on what I'm missing. If I figure it out before an answer, thanks for looking at it in advance.

#include <iostream>
using namespace std;

// This program outputs the balance on a revolving credit account, interest due, and minimum
// payment due. The interest is computed as follows: 1.5% tax on the first $1,000 of
// the balance plus 1.0% on any balance over $1,000.


int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

int balance, total_due, minimum_payment_due, new_balance, interest_due;
double one_five_percent_interest, one_percent_interest;
double credit_balance, min_due;


cout << "Enter your balance: $";
cin >> balance;

one_five_percent_interest = 0.015;
one_percent_interest = 0.01;

if (balance <= 1000)
credit_balance = one_five_percent_interest * balance;

if ((balance > 1000) && (balance <= 99999999999999))
credit_balance = (one_percent_interest*(balance - 1000))*one_five_percent_interest;
cout << " Your interest due is $"
<< credit_balance;

cout << " Your new balance is. $" << credit_balance + balance;

new_balance = credit_balance + balance;

if (new_balance <=10)
min_due = new_balance;

else if ((new_balance > 10))
min_due = .10 * new_balance;

cout << " Your minimum payment due is. $" << min_due;



char answer;

cout << " Would you like to type another balance (1 = Yes \ 0 = No)? ";

if (answer == '1')
cout << "Enter your balance: $";
cin >> balance;

cout << "\n";


return 0;

}
You could try something like this:

1
2
3
4
5
6
7
8
9
char answer; // declare this outside the loop
do
{
   // .. stuff

   cout << "Again? [1 = yes, 0 = no] ";
   cin >> answer; 
}
while(answer == '1');
Is the 9999999999999 test really necessary?

1
2
3
	if((balance > 1000) && (balance <= 99999999999999))
		credit_balance = (one_percent_interest * (balance - 1000))
			* one_five_percent_interest;


Also if interest is 1.5% on first 1000 and 1.0% thereafter I would have thought you need something like this:

1
2
3
double first_interest = 1000 * 1.5 / 100;
double other_interest = (balance - 1000) * 1.0 / 100;
credit_balance = first_interest + other_interest; 


Unless I missed something...
Last edited on
thanks a lot with a few minor changes everything was ok. Here's the new code.

#include <iostream>
using namespace std;

// This program outputs the balance on a revolving credit account, interest due, and minimum
// payment due. The interest is computed as follows: 1.5% tax on the first $1,000 of
// the balance plus 1.0% on any balance over $1,000.


int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

int total_due, new_balance, balance;
double credit_balance;
double min_due;
double first_interest;
double other_interest;

char answer;

do
{

cout << "Enter your balance: $";
cin >> balance;

first_interest = balance * 1.50 / 100;
other_interest = first_interest * 1.0 / 100;


if (balance <= 1000)
credit_balance = first_interest;

else if (balance > 1000)
credit_balance = other_interest + first_interest;

new_balance = credit_balance + balance;

cout << " Your interest due is $"
<< credit_balance;

cout << " Your new balance is. $" << credit_balance + balance;

if (new_balance <=10)
min_due = balance;

else if (new_balance > 10)
min_due = .10 * new_balance;

cout << " Your minimum payment due is. $" << min_due;



cout << " Again? [1 = Yes \ 0 = No] ";
cin >> answer;

}
while (answer == '1');






}
Topic archived. No new replies allowed.