Hello, I am trying to print the following: Month Balance Interest Payment 1 $ 10
ID: 3619951 • Letter: H
Question
Hello, I am trying to print the following:Month Balance Interest Payment
1 $ 10050.00 $ 100.50 $ 500.00
2 $ 9650.50 $ 96.51 $ 500.00
3 $ 9247.01 $ 92.47 $ 500.00
4 $ 8839.48 $ 88.39 $ 500.00
Now I can get everything to print besides the dollar signs. I am required to use the cout command and the setw, setprecision commands. Is there any way to get the cout command to print a string + a double. I need both the $ and the double to respect the setw() command. So far I have been unable to accomplish that. My code so far looks like this:
int main (int argc, char * const argv[]) {
cout.precision(2);
double interest;
cout << "Month " << "Balance " << setw(8) << "Interest " << setw(10) << "Payment" <<" ";
double balance = 10050.00;
double payment = 500;
for(int a = 1; a<5; a++)
{
interest = balance*.01;
cout << fixed << setw(6) << a << setw(15) << balance << setw(14) << interest << setw(13) << payment << endl;
balance = balance - payment+interest;
}
return 0;
}
Explanation / Answer
Modify your cout statement as follows: coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.