C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Menu Driven Simple Interest and Compound Interest Program in C

Introduction

This program combines multiple SI & CI functionalities into a single interactive program.
Users can choose options from a menu, and the program will perform calculations or generate tables/graphs accordingly.

This makes it flexible and user-friendly, ideal for practice and teaching.

Menu-Driven C Program for SI & CI where the user can:

  • Calculate Simple Interest
  • Calculate Compound Interest
  • Find Difference between SI & CI
  • Generate Year-wise Comparison Table
  • Show Graphical Comparison (ASCII Bars)

 

C Program: Menu Driven Simple Interest and Compound Interest Program

C

#include <stdio.h>

#include <math.h>

 

// Function to calculate Simple Interest

float simpleInterest(float p, float r, float t) {

    return (p * r * t) / 100;

}

 

// Function to calculate Compound Interest

float compoundInterest(float p, float r, float t) {

    float amount = p * pow((1 + r / 100), t);

    return amount - p;

}

 

// Function to print ASCII bar for visualization

void printBar(float value) {

    int length = (int)(value / 10); // scale down for console

    for (int i = 0; i < length; i++) {

        printf("#");

    }

}

 

int main() {

    float principal, rate, time;

    int choice, years, i;

 

    // Input values

    printf("Enter Principal amount: ");

    scanf("%f", &principal);

 

    printf("Enter Rate of Interest (in %%): ");

    scanf("%f", &rate);

 

    printf("Enter Time (in years): ");

    scanf("%f", &time);

 

    do {

        printf("\n===== Interest Menu =====\n");

        printf("1. Calculate Simple Interest\n");

        printf("2. Calculate Compound Interest\n");

        printf("3. Difference between SI and CI\n");

        printf("4. Year-wise Comparison Table\n");

        printf("5. Graphical Comparison (SI vs CI)\n");

        printf("0. Exit\n");

        printf("Enter your choice: ");

        scanf("%d", &choice);

 

        switch (choice) {

            case 1: {

                float si = simpleInterest(principal, rate, time);

                printf("\nSimple Interest = %.2f\n", si);

                break;

            }

            case 2: {

                float ci = compoundInterest(principal, rate, time);

                printf("\nCompound Interest = %.2f\n", ci);

                break;

            }

            case 3: {

                float si = simpleInterest(principal, rate, time);

                float ci = compoundInterest(principal, rate, time);

                printf("\nDifference (CI - SI) = %.2f\n", ci - si);

                break;

            }

            case 4: {

                years = (int)time;

                printf("\nYear | Simple Interest | Compound Interest\n");

                printf("------------------------------------------\n");

                for (i = 1; i <= years; i++) {

                    float si = simpleInterest(principal, rate, i);

                    float ci = compoundInterest(principal, rate, i);

                    printf("%4d | %.2f\t\t %.2f\n", i, si, ci);

                }

                break;

            }

            case 5: {

                years = (int)time;

                printf("\nYear | Simple Interest (Bar) | Compound Interest (Bar)\n");

                printf("---------------------------------------------------------\n");

                for (i = 1; i <= years; i++) {

                    float si = simpleInterest(principal, rate, i);

                    float ci = compoundInterest(principal, rate, i);

 

                    printf("%4d | ", i);

                    printBar(si);

                    printf(" (%.2f)", si);

 

                    printf("\t| ");

                    printBar(ci);

                    printf(" (%.2f)\n", ci);

                }

                break;

            }

            case 0:

                printf("\nExiting program. Thank you!\n");

                break;

 

            default:

                printf("\nInvalid choice! Please try again.\n");

        }

    } while (choice != 0);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter Principal amount: 1000
Enter Rate of Interest (in %): 10
Enter Time (in years): 5

===== Interest Menu =====
1. Calculate Simple Interest
2. Calculate Compound Interest
3. Difference between SI and CI
4. Year-wise Comparison Table
5. Graphical Comparison (SI vs CI)
0. Exit
Enter your choice: 4

Year | Simple Interest | Compound Interest
------------------------------------------
   1 | 100.00          100.00
   2 | 200.00          210.00
   3 | 300.00          331.00
   4 | 400.00          464.10
   5 | 500.00          610.51


OUTPUT 2 :

Enter Principal amount: 1000
Enter Rate of Interest (in %): 10
Enter Time (in years): 5

===== Interest Menu =====
1. Calculate Simple Interest
2. Calculate Compound Interest
3. Difference between SI and CI
4. Year-wise Comparison Table
5. Graphical Comparison (SI vs CI)
0. Exit
Enter your choice: 1

Simple Interest = 500.00

===== Interest Menu =====
1. Calculate Simple Interest
2. Calculate Compound Interest
3. Difference between SI and CI
4. Year-wise Comparison Table
5. Graphical Comparison (SI vs CI)
0. Exit
Enter your choice: 2

Compound Interest = 610.51

===== Interest Menu =====
1. Calculate Simple Interest
2. Calculate Compound Interest
3. Difference between SI and CI
4. Year-wise Comparison Table
5. Graphical Comparison (SI vs CI)
0. Exit
Enter your choice: 0

Exiting program. Thank you! 



Explanation

  • Functions are used for SI, CI, and Bar printing.
  • A menu system (switch-case) allows the user to select an option.
  • do-while loop keeps showing the menu until the user exits.
  • Both numeric (table) and visual (ASCII bar graph) comparisons are included.