Thread: Help with Program

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    1

    Help with Program

    Hello I'm new to the forum and to to C programming as well. I'm having a little bit of a problem with my code. You see, my program is an enrollment system and asks which subject you want to enroll. But every time i run the code and compute for the total, the addition seems wrong. Please help

    here's my code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
        int n,none,ntwo,nthree,Total;
        float Algebra,Trigonometry,Calculus,Engiana,Physics;
        char password[20],username[8];
        Algebra = 100;
        Trigonometry = 300;
        Calculus = 500;
        Engiana = 750;
        Physics = 1500;
        Total = (none+ntwo+nthree);
    
    
        printf("Welcome to the Enrollment System \n");
        printf("Here is the list of Available Subjects \n");
        printf("\n");
        printf("Course Code         Price\n");
        printf("\n");
        printf("1. Algebra             %.2f \n",Algebra);
        printf("2. Trigonometry        %.2f \n",Trigonometry);
        printf("3. Calculus            %.2f \n",Calculus);
        printf("4. Engiana             %.2f \n",Engiana);
        printf("5. Physics             %.2f \n",Physics);
        
        printf("You can only select three courses to enroll for the Term \n");
        printf("\n Select First Course to Enroll \n");
        scanf("%d", &none);
     
         switch(none) 
        {
                 case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
                 case 2: printf(" You Enrolled Trigonometry %.2f \n", Trigonometry); break; //if conditions not met goes to another case
                 case 3: printf(" You Enrolled Calculus %.2f \n", Calculus); break;
                 case 4: printf(" You Enrolled Engiana %.2f \n", Engiana); break;
                 case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
                 default: printf(" The Course you entered is not valid \n"); break;
                 }
                    printf("\n Select Second Course to Enroll \n");
                    scanf("%d", &ntwo);
                    
                  switch(ntwo) 
        {
                 case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
                 case 2: printf(" You Enrolled Trigonometry %.2f\n", Trigonometry); break; //if conditions not met goes to another case
                 case 3: printf(" You Enrolled Calculus %.2f\n", Calculus); break;
                 case 4: printf(" You Enrolled Engiana %.2f\n", Engiana); break;
                 case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
                 default: printf(" The Course you entered is not valid \n"); break;
                 }
                     printf("\n Select Third Course to Enroll \n");
                     scanf("%d", &nthree);
                  switch(nthree) 
        {
                 case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
                 case 2: printf(" You Enrolled Trigonometry %.2f \n", Trigonometry); break; //if conditions not met goes to another case
                 case 3: printf(" You Enrolled Calculus %.2f \n", Calculus); break;
                 case 4: printf(" You Enrolled Engiana %.2f \n", Engiana); break;
                 case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
                 default: printf(" The Course you entered is not valid \n"); break;
                 }
      printf("Total Tuition Price = %.2f \n",Total);
    system("PAUSE");
    return 0;
    }
    Last edited by justins19; 08-19-2013 at 02:16 AM.

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    The calculation for total needs to be done within the three sets of switch / case statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM