Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (roadjester):

My program won't print the amount interest. Can someone help me debug?

OpenStudy (roadjester):

#include <iostream> #include <cstdlib> //***************************************************** //Project: Interest //Author: //Purpose: Computes the interest on a credit card account balance. //Notes: 9/23/12 //****************************************************** using namespace std; //prototypes double accountInterest(double intBal, double moRate, double numMonths); double posDouble(string prompt); void Print(double intBal, double moRate, double numMonths); int main() { double numMonths=0; double intBal=0; double moRate=0; double interest=0; char answer=' '; do { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); intBal=posDouble("Initial balance: $"); moRate=posDouble("Rate: "); cout.precision(0); numMonths=posDouble("Number of months: "); interest=accountInterest(intBal, moRate, numMonths); Print(intBal, moRate, numMonths); cout<<"Would you like to repeat this calculation?"<<endl<<endl; cout<<"Answer: "; cin>>answer; cout<<endl; }while ((answer=='Y')||(answer=='y')); system("PAUSE"); return 0; } double posDouble(string prompt) { double number; cout<<prompt; cin>>number; cout<<endl; while (number<=0) { cout<<"Enter a positive value."<<endl<<endl; cout<<prompt; cin>>number; cout<<endl; } return number; } double accountInterest(double intBal, double moRate, double numMonths) { while (numMonths>0) { intBal=intBal*(1+(moRate/100)); numMonths--; } return intBal; } void Print(double intBal, double moRate, double numMonths) { double interest; cout.precision(2); cout<<"An initial balance of $"<<intBal<<" with a monthly" <<" "<<"interest rate of "; cout.precision(1); cout<<moRate<<"%"<<" for "<<numMonths <<" months yields"; cout.precision(2); cout<<" $"<<interest<<"."<<endl<<endl; }

OpenStudy (bahrom7893):

it compiles here

OpenStudy (roadjester):

true, it will compile, but it won't output the amount interest. by the way, what compiler are you using? is there a compiler on openstudy?

OpenStudy (roadjester):

@bahrom7893

OpenStudy (anonymous):

You're printing the wrong interest value. You're not passing it through your print function, you're just defining it as a new double and never setting it. you need to change this line: Print(intBal, moRate, numMonths); and this line: void Print(double intBal, double moRate, double numMonths) and remove this line: double interest;

OpenStudy (bahrom7893):

oh sorry, i opened it late last night and I thought that u said it wouldn't compile.

OpenStudy (bahrom7893):

And I use Bloodshed wxDev-C++

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!