Author |
Anyone good with C+ another question |
garlic_bread Joined: Jul 20, 2006 Posts: 330 PM |
Ok so i had to write a program to calculate how many months it will take to pay of Xloan with Yinterest
So the program works and calculates everything but then instantly closes.
How do i stop it from closing?
#include
#include
int main (void)
{
float loan, rate, payment;
int month=0;
printf("amount of loan = ");
scanf("%f", &loan);
printf("monthly interest rate = ");
scanf("%f", &rate);
printf("payment per month = ");
scanf("%f", &payment);
while (loan>0.0)
{
month++;
loan = loan + (loan*rate/100);
loan=loan-payment;
printf("in month %d the sum remaining is = %fn", month, loan);
}
printf("it will take %d months to payn", month);
getchar();
}
[ This Message was edited by: garlic_bread on 2009-11-05 23:39 ] |
|
tranced Joined: Jan 19, 2006 Posts: > 500 From: Santo Domingo, wonDeRland PM |
IMO, you need a: system("pause"); at the end
|
garlic_bread Joined: Jul 20, 2006 Posts: 330 PM |
haha, do you think that will be classed as cheating?
|
tranced Joined: Jan 19, 2006 Posts: > 500 From: Santo Domingo, wonDeRland PM |
If (it works)
Printf("yes");
Else
Printf("Failed help");
|
garlic_bread Joined: Jul 20, 2006 Posts: 330 PM |
printf("works great thank you very much");
|
tranced Joined: Jan 19, 2006 Posts: > 500 From: Santo Domingo, wonDeRland PM |
that was cheating then
you had the program done. you just needed a bit of help. it could not be considered as cheating.
|
garlic_bread Joined: Jul 20, 2006 Posts: 330 PM |
Can you see any main erros in this ?
#include
#define PI
void calcCircle(float radius, float*area, float*circum);
int void (main)
{
float radius, area, circum;
float*apt
printf("Enter the radius of your circle:")
apt=&area
calcCircle(radius,apt,&circum);
printf("A circle of radius %f\\n\\t has area %f\\n\\t and circumference %f",radius,area,circum);
return 0;
void calcCircle(f, float*area, float*circum)
{
float pi=PI;
*area=pi*radius*radius;
*circum=2.0*pi*radius;
}
return 0;
}
|
|
Access the forum with a mobile phone via esato.mobi
|