We read your photo as:
What are the errors in this C program for calculating simple interest, and how can they be fixed?
ScanSolve AI Answer
Answer
Yes, there are a couple of errors in the C program.
The main issue is a consistent misspelling of the variable principal.
-
Incorrect variable name in
scanffor principal: You declared the variable asfloat principal;but then tried to read input into&principalAmtin thescanffunction. The variableprincipalAmtis not declared. It should be&principal.Original:
scanf("%f", &principalAmt);
Corrected:
scanf("%f", &principal); -
Incorrect variable name in simple interest calculation: Similarly, in the calculation for
SI, you usedprincipleAmtinstead ofprincipal.Original:
SI = (principleAmt * time * rate) / 100;
Corrected:
SI = (principal * time * rate) / 100;
Here is the corrected code:
#include<stdio.h>
int main() {
float principal;
float rate;
float time;
float SI;
printf("ENTER THE PRINCIPLE AMT\n");
scanf("%f", &principal); // Corrected: used 'principal'
printf("ENTER THE RATE\n");
scanf("%f", &rate);
printf("ENTER THE TIME\n");
scanf("%f", &time);
//calculate the simple interest
SI = (principal * time * rate) / 100; // Corrected: used 'principal'
//display the calculated interest to the user
printf("INTEREST:%f\n", SI);
return 0;
}
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.