Task:Make a program which can show the money left owed to the user while the user inputs the money owed total and the amount he can pay each month.
After each month, show the user how much he is left owed, he CANNOT repay more then the amount neccesary!
Example User owes total of 120$
1. month – 35$ (left owed 85$)
2. month – 50$ (left owed 35$)
3. month – 12$ (left owed 23$)
4. month – 23$ (left owed 0$)
I got this far but have no idea why my program just doesn't calculate the ''left owed'' and doesn't stop when the guy actually pays everything lol
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main()
{
clrscr();
int x, y, sum=0;
cout<< "Input total amount owed ";
cin>> x;
do
{
cout <<"Input amount you can repay each month: ";
cin >>y;
if (x>y) sum=sum+y;
}
while (x=sum);
cout <<"\nMoney left owed: "<<sum;
getch();
}
#include <math.h>
#include <conio.h>
int main()
{
clrscr();
int x, y, sum=0;
cout<< "Input total amount owed ";
cin>> x;
do
{
cout <<"Input amount you can repay each month: ";
cin >>y;
if (x>y) sum=x-y;
cout <<"\nMoney left owed: "<<sum;
}
while (x>=sum);
getch();
}
now when i input a number for example 30 total and 10 in the 1st month it shows money left owed''10''? And program stops...
Ok so now i think i fixed the sum part with
sum=x-y, but however it just shows it correctly the 1st month
like i put in 30 total and 10 first it correctly shows that the user owes 20 more however when i repeat this with another 10 it again shows 20, why
your condition must be like this if(x>=y)you should put another variable their e.g int variable=0; and do this variable=x-sum; and then
change this cout<<"\nMoney left owed: "<<variable
and your while condition can should be this while(x>0);
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main()
{
clrscr();
int x, y, sum=0, n=0;
cout<< "Input total amount owed ";
cin>> x;
do
{
cout <<"Input amount you can repay each month: ";
cin >>y;
if (x>=y) n=x-sum;
cout <<"\nMoney left owed: "<<n;
}
while (x>0);
getch();
}
However at that point the ''sum'' is still 0 which doesn't quite make the program work.
If however i put x-y, it does show the correct result the 1st time
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main()
{
clrscr();
int x, y, sum=0, n=0;
cout<< "Input total amount owed ";
cin>> x;
do
{
cout <<"Input amount you can repay each month: ";
cin >>y;
if(x>=y)
{
sum=x-y;
n=x-sum;
cout<<"\nMoney left owed: "<<n;
}
}
while (x>0);
getch();
}
it still doesn't remember the new total amount left owed.