microsoft visual studio

my advance thanks to anyone who can help me in this program. the problem is the program only calculates the first month only it does not follow up can someone help in it??? i know its very beginner its for school project. please note that i only can use microsoft visual studio plus i can't use #include<iostream>.
it has to be #include<stdio.h> and void main(void).




#include <stdio.h>
#include <conio.h>
#include <math.h>
void main(void)
{
float monthlyPayment;
float balance;
float interestRate;
float cout;
float rate;
float remainder, remainder1, remainder2;
float balance1;
int choice;
printf("This progame will calculate your monthly compound interest:\n");
printf("Enter a choice [ 0=Quit, 1=calculate compound interest] :\n");
scanf("%d", &choice);
switch (choice)
{
case 0 : printf("Bye Bye!!");
break;
case 1 :
printf("Enter the current balance of your loan: ");
scanf("%f", &balance);
printf("Enter the interest rate (compounded monthly) : ");
scanf("%f",&interestRate);
printf("Enter the desired monthly payment : ");
scanf("%f", &monthlyPayment);
break;
default : printf(" invalid.");
printf("bye bye");
}
if (interestRate >= 1)
{
rate = interestRate / 100;

remainder = balance * (1 + rate / 12) - monthlyPayment;

printf("\nAfter month 1 your balance is $%.2f", remainder);
}

else
{

if (balance > 0)

{
remainder = balance * (1 + rate / 12) - monthlyPayment;

}

else

{

if (remainder < monthlyPayment)
{
printf("\nLast month payment is $%.2f ", remainder);
remainder1 = balance - balance1;

}
else
{
remainder2 = balance * (1 + (rate / 12)) - monthlyPayment;
}
}
}
printf("\nYou still haven't paid off your loan.!");


getch ();

}
You need a loop in order to do something more than once. Like so:
1
2
3
4
5
6
7
8
9
int choice;
do
{
printf("This progame will calculate your monthly compound interest:\n");
printf("Enter a choice [ 0=Quit, 1=calculate compound interest] :\n");
scanf("%d", &choice);
...
}
while(choice != 0);



Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
okay may i know where do you input this code in my program
closed account (17ihb7Xj)
The code that coder777 gave you is a loop. When you look at a loop (in this case a do{} while() loop) you can see that any code that you want executed goes in between the do squiggly braces of the do{} part of the loop, like this:

1
2
3
4
5
6
7
8
do
{
/*Insert some code here
put more of the code here
....
....
....*/
}


The while conditional statement determines how long the loop will last. In this case, you will continue to run the program until you enter 0. For safety, I would recommend adding in a check to make sure the user has not put in a wrong value. For example, the program will still run if one were to put in 5, although 5 is not a valid choice for your program.
Last edited on
Topic archived. No new replies allowed.