Thread: Educational Loan

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    3

    Educational Loan

    Please help me with this one, i think the problem is in the functions and the switch. How can i correct my program?
    //Educational loan
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    void Hello(void){
        printf("Hello and welcome to Demigod's Electronic Loan Amortization Calculator. Here we will make a table for you when given the amount of the loan, the interest rate, and the number pf payments you wish to have.\n\nPress any key to continue...");
        getch();
        system("cls");
        printf("Okay.. we will first need some basic information about you and your loan.");
    }
    
    int Info(void){
        int age;
        printf("\n\nInput your age:\t");
        scanf("%d", &age);
        if(age<18){
            printf("\nSorry, you are not allowed to avail a loan.");
            
            return 0;
        }
    }
    void Select(void){
        printf("\n\nSelect the number of periods you want to make to pay this loan off:");
        printf("\n\t\t\t[1] - MONTHLY");
        printf("\n\t\t\t[2] - QUARTERLY");
        printf("\n\t\t\t[3] - SEMI-ANNUALLY");
        printf("\n\t\t\t[4] - ANUUALLY");
        printf("\n\t\t\t[0] - Exit");
        
    }
    
    float Mon(void){
        float Monpay, Intpay, lg, i;
        Monpay=lg/36;
        Intpay=(lg*i)/36;
        printf("\nMonthly Payment:\t%.2f", Monpay);
        printf("\nInterest Payment:\t%.2f", Intpay);
        printf("\nTotal Monthly Payment:\t%.2f", Monpay+Intpay);
        return Monpay, Intpay;
    }
    
    float Quar(float amt, float interest){
        float Quarpay, Intpay, lg, i;
        Quarpay=lg/12;
        Intpay=(lg*i)/12;
        printf("\nMQuarterly Payment:\t%.2f", Quarpay);
        printf("\nInterest Payment:\t%.2f", Intpay);
        printf("\nTotal Quarterly Payment:\t%.2f", Quarpay+Intpay);
        return Quarpay, Intpay;
    }
    
    float Semi(float amt, float interest){
        float Semipay, Intpay, lg, i;
        Semipay=lg/6;
        Intpay=(lg*i)/6;
        printf("\nSemi-Annual Payment:\t%.2f", Semipay);
        printf("\nInterest Payment:\t%.2f", Intpay);
        printf("\nTotal Semi-Annual Payment:\t%.2f", Semipay+Intpay);
        return Semipay, Intpay;
    }
    
    float Annual(float amt, float interest){
        float Annualpay, Intpay, lg, i;
        Annualpay=lg/3;
        Intpay=(lg*i)/3;
        printf("\nAnnual Payment:\t%.2f", Annualpay);
        printf("\nInterest PAyment:\t%.2f", Intpay);
        printf("\nTotal Annual Payment:\t%.2f", Annualpay+Intpay);
        return Annualpay, Intpay;
    }
    
    
    
    main(){
        int age, styp, option;
        float PAI, lg, i, Monpay, Quarpay, Semipay, Annualpay;
        char lt, name[50];
        
        Hello();
        printf("\n\nInput your full name:\t");
        gets(name);
        Info();
        
        
        do{
            printf("\nInput type of school (Press '1' if PRIVATE, '2' if PUBLIC):\t");
            scanf("%d", &styp);
            if(styp<1||styp>2){
                printf("Erroneous input. Press 1 or 2 only.");
            }
        }while(styp<1||styp>2);
        
        printf("\nInput Parent's Annual Income:\t");
        scanf("%f", &PAI);
        
        if(styp==2){
            if(PAI<40000){
                    do{
                        printf("\n\nInput Loan Amount (15,000-25,000 only):\t");
                        scanf("%f", &lg);
                        if(lg<15000||lg>25000){
                            printf("\nYou are not allowed to avail a loan below 15,000 or greater than 25,000. \nPlease enter another amount.");
                        }
                    }while(lg<15000||lg>25000);
                
                i=0.06;
                lt='B';
            }else{
                    do{
                        printf("\n\nInput Loan Amount (25,000-45,000 only):\t");
                        scanf("%f", &lg);
                        if(lg<25000||lg>45000){
                            printf("\nYou are not allowed to avail a loan below 25,000 or greater than 45,000. \nPlease enter another amount.");
                        }
                    }while(lg<25000||lg>45000);
                i=0.10;
                lt='A';
            }
        }else
            if(styp==1){
            if(PAI<40000){
                    do{
                        printf("\n\nInput Loan Amount (45,000-65,000 only):\t");
                        scanf("%f", &lg);
                        if(lg<45000||lg>65000){
                            printf("\nYou are not allowed to avail a loan below 45,000 or greater than 65,000. \nPlease enter another amount.");
                        }
                    }while(lg<45000||lg>65000);
                i=0.08;
                lt='B';
            }else{
                    do{
                        printf("\n\nInput Loan Amount (65,000-85,000 only):\t");
                        scanf("%f", &lg);
                        if(lg<65000||lg>85000){
                            printf("\nYou are not allowed to avail a loan below 65,000 or greater than 85,000. \nPlease enter another amount.");
                        }
                    }while(lg<65000||lg>85000);
                i=0.12;
                lt='A';
            }
        }
        do{
            system("cls");
            do{
                Select();
                printf("\n\nInput your choice:\t");
                scanf("%d", &option);
                if(option<0 || option>4);
                    printf("\nWrong input. Only 0-4 is allowed.");
            }while(option<0 || option>4);
            system("cls");
            
            switch(option){
            case 1: Mon();
                    break;
            case 2: Quarpay = Quar(lg, i);
                    break;
            case 3: Semipay = Semi(lg, i);
                    break;
            case 4: Annualpay = Annual(lg, i);
                    break;
            }
            printf("\n\nPress any key to continue...");
            getch();        
        }while(option != 0);
    
        printf("\nLoan type:\t%c", lt);
        printf("\nLoan granted:\t%.2f", lg);
        printf("\nAnnual interest rate:\t%.2f", i);
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Why don't you start by telling us specifically what the problem is?
    Posting warnings and errors reported by your compiler would also be good.

    You appear to be using several uninitialized variables, perhaps start there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 02-10-2011, 11:17 AM
  2. Replies: 0
    Last Post: 02-09-2011, 11:32 AM
  3. Educational std for software developers?
    By camelCase in forum Tech Board
    Replies: 6
    Last Post: 07-22-2010, 10:28 PM
  4. Educational WebCasts
    By JarJarBinks in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-07-2004, 10:49 AM

Tags for this Thread