We read your photo as:

What are the errors in this C program for calculating simple interest, and how can they be fixed?

Computer Science

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.

  1. Incorrect variable name in scanf for principal: You declared the variable as float principal; but then tried to read input into &principalAmt in the scanf function. The variable principalAmt is not declared. It should be &principal.

    Original:
    scanf("%f", &principalAmt);
    Corrected:
    scanf("%f", &principal);

  2. Incorrect variable name in simple interest calculation: Similarly, in the calculation for SI, you used principleAmt instead of principal.

    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;
}
Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question