I'm new to coding C.
I wrote a basic program for calculating interest (the method of calculating simple interests is incorrect, but this is not the place where the current problem lies). I am inserting the code here so you can better understand the problem.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("This is a program which calculates your balance each year for 5 years! \n");
char name [30];
float principal;
float interestRate;
int interestType;
int age;
printf("Start by entering your name \n");
scanf("%s", name);
printf("Please enter the type of interest you earn (Simple = 1, Compound = 2) \n");
scanf("%d", interestType);
if (interestType == 1)
{
printf("You have chosen your interest type as simple \n");
printf("Please enter your age \n");
scanf(" %d", &age);
if (age < 18)
{
printf("You're not eligible for a bank account yet");
}
else if (age > 122)
{
printf("Please submit your age to the Guinness Book of World Records and try again");
}
else
{
printf("Please enter your current account balance \n");
scanf(" %f", &principal);
if (principal == 0)
{
printf("You don't have any balance, please fill money in your account and try again \n");
}
else
{
printf("Please enter the rate of interest at which your money is being multiplied \n");
scanf(" %f", &interestRate);
principal = principal + interestRate;
printf("%s balance after 1 year will be %f \n", name, principal);
principal = principal + interestRate;
printf("%s balance after 2 years will be %f \n", name, principal);
principal = principal + interestRate;
printf("%s balance after 3 years will be %f \n", name, principal);
principal = principal + interestRate;
printf("%s balance after 4 years will be %f \n", name, principal);
principal = principal + interestRate;
printf("%s balance after 5 years will be %f \n", name, principal);
printf("Thats all");
}
}
}
else if (interestType == 2)
{
printf("You have chosen your interest type as compound \n");
printf("Please enter your age \n");
scanf(" %d", &age);
if (age < 18)
{
printf("You're not eligible for a bank account yet");
}
else if (age > 122)
{
printf("Please submit your age to the Guinness Book of World Records and try again");
}
else
{
printf("Please enter your current account balance \n");
scanf(" %f", &principal);
if (principal == 0)
{
printf("You don't have any balance, please fill money in your account and try again \n");
}
else
{
printf("Please enter the rate of interest at which your money is being multiplied \n");
scanf(" %f", &interestRate);
principal *= interestRate;
printf("%s balance after 1 year will be %f \n", name, principal);
principal *= interestRate;
printf("%s balance after 2 years will be %f \n", name, principal);
principal *= interestRate;
printf("%s balance after 3 years will be %f \n", name, principal);
principal *= interestRate;
printf("%s balance after 4 years will be %f \n", name, principal);
principal *= interestRate;
printf("%s balance after 5 years will be %f \n", name, principal);
printf("Thats all");
}
}
}
return 0;
}
The problem I am facing is that whenever a program starts up and asks for the type of interest, after entering the input number (1 or 0) it just stops.
source
share