Logic/Runtime Error Assistance ASAP.

This is a discussion on Logic/Runtime Error Assistance ASAP. within the C Programming forums, part of the General Programming Boards category; Please, I have created this program and have debugged and improved for hours. This programm was done in oder to ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Logic/Runtime Error Assistance ASAP.

    Please, I have created this program and have debugged and improved for hours. This programm was done in oder to print 3 stands are allow the user to choose their stand and seat, repeatedly updating records. This portion of the code is fine. In addition to this one must calculate various total costs, standwise and patron classification wise and at the end display them. My display at the end refuses to show, instead crashing the program, I am at my wits end, please! I beg!


    The two portions I believe are problematic are:

    Code:
    Calculate_ClassRevenue(int Patrprice)
    {
               if(Patrprice==childcost)
               {
                     totalccost=Patrprice+totalccost;
                     ccostptr=&totalccost;
               }
               else if(Patrprice==adultcost)
               {
                    totalacost=Patrprice+totalacost;
                    acostptr=&totalacost;
               }  
               else if(Patrprice==seniorcost)
               {
                    totalscost=Patrprice+totalscost;
                    scostptr=&totalscost;
               }
               
    }

    AND
    Code:
    void Display_EndData()
         {
              
              int totalccost,totalacost,totalscost;
              totalccost=*ccostptr;
              totalacost=*acostptr;
              totalscost=*scostptr;
              printf("The total amount provided by children is: %d",totalccost);
              printf("The total amount provided by adults is: %d",totalacost);
              printf("The total amount provided by senior citizens is: %d",totalscost);
             
         }












    FULL CODE:


    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    
    #define childcost 80
    #define adultcost 120
    #define seniorcost 60
    
    #define totempty 2
    
    int standA[19]={0}, standB[19]={0}, standC[19]={0};
    
    
    int totaltaken=0,totalavailable=0;
    int Ataken=0,Btaken=0,Ctaken=0;
    int Aleft=0,Bleft=0,Cleft=0;
    
    
    char Determine_StandChoice(char);
    void Display_EndData();
    
    
    
    int i;
    int *acostptr,*scostptr,*ccostptr,*ageptr;
    int totalccost,totalacost,totalscost;
    
    int TotStandA,TotStandB,TotStandC;
    
    
    main()
    {
          char standch;
          int i,vacant,cost;
          int total_cost=0;
          
          int Atot=0,Btot=0,Ctot=0;
          
             
               
          
                
                AStand();
                BStand();
                CStand();
                getch();
                system("cls");
                Accepting_PatronInput();
                
                getch();
                
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int Accepting_PatronInput()
    {
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
         int age,standch,Patrprice;
         while(totaltaken !=totempty)
         { 
                          do
                          {
                          SetConsoleTextAttribute(hConsole,775);
                          printf("Please enter the");
                          SetConsoleTextAttribute(hConsole,783);  
                          printf(" age ");
                          SetConsoleTextAttribute(hConsole,775);
                          printf("of the patron.\n");                      
                          SetConsoleTextAttribute(hConsole,783);
                          scanf("%d",&age);
                          }while(age<=0);
                          printf("\n\n\nIn order to terminate:\n");
                          SetConsoleTextAttribute(hConsole,783);  
                          printf("Enter E ");
                          SetConsoleTextAttribute(hConsole,775);
                          printf("in the stand field.\n\n\n");
                          SetConsoleTextAttribute(hConsole,783);
                          printf("The options are: 'A','B' or 'C'\n");
                          SetConsoleTextAttribute(hConsole,775); 
                          printf("Please enter the stand.\n");
                          SetConsoleTextAttribute(hConsole,783);
                          scanf("%s",&standch);                   
                          
                          SetConsoleTextAttribute(hConsole,775); 
                          
                           
                                                                             
                          
                          ageptr=&age;                     
                          Determine_StandChoice(standch);
                          getch();                    
                          system("cls");
                          
                          
                        
                          
                          
         }
    }
         void Display_EndData()
         {
              int dummy;
              int totalccost,totalacost,totalscost;
              totalccost=*ccostptr;
              totalacost=*acostptr;
              totalscost=*scostptr;
              printf("The total amount provided by children is: %d",totalccost);
              printf("The total amount provided by adults is: %d",totalacost);
              printf("The total amount provided by senior citizens is: %d",totalscost);
              scanf("%d", &dummy);
         }
    
    
       
    
    char Determine_StandChoice(char standch)
    {
         HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
                
         switch(standch)
         {
                        case 'A':StandASeating();
                        break;
                        case 'B':StandBSeating();
                        break;
                        case 'C':StandCSeating();
                        break;
                        case 'E':exit(0);
                        break;
                        default:SetConsoleTextAttribute(hConsole,777);
                                printf("\nThis is not an aviable option, please re-select the stand.");
                                SetConsoleTextAttribute(hConsole,775);
                                printf("\n\n\nIn order to terminate:\n");
                                SetConsoleTextAttribute(hConsole,783);  
                                printf("Enter E ");
                                SetConsoleTextAttribute(hConsole,775);
                                printf("in the stand field.\n\n\n");
                                SetConsoleTextAttribute(hConsole,783);
                                printf("The options are: 'A','B' or 'C'\n");
                                SetConsoleTextAttribute(hConsole,775); 
                                printf("Please enter the stand.\n");
                                SetConsoleTextAttribute(hConsole,783);
                                scanf("%s",&standch);             
                                Determine_StandChoice(standch);             
         }
    }
         
    int StandASeating()
    {
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        int i,age,PatrpriceA;
        printf("\n\n\nPlease enter the");
        SetConsoleTextAttribute(hConsole,783);
        printf(" seat:\n");
        scanf("%d",&i);
        i=i-1;
        age=*ageptr;
        if(standA[i]==0)
        {               PatrpriceA=Determine_PatronPrice(age);
                        TotStandA=PatrpriceA+TotStandA;
                        standA[i]=1;
                        totaltaken++;
                        Ataken++;
                        system("cls");
                        if(totaltaken==totempty)
                        {       AStand();
                                BStand();
                                CStand();                
                                Display_EndData();
                        }
                        AStand();
                        BStand();
                        CStand();
        }
        else if(standA[i]==1)
        {
             printf("That seat is taken!Please re-enter your information.");
             AStand();
             BStand();
             CStand();
        }
    }
    
    int StandBSeating()
    {
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        int i,age,PatrpriceB;
        printf("\n\n\nPlease enter the");
        SetConsoleTextAttribute(hConsole,783);
        printf(" seat:\n");
        scanf("%d",&i);
        i=i-1;
        age=*ageptr;
        if(standB[i]==0)
        {
                        PatrpriceB=Determine_PatronPrice(age);
                        TotStandB=PatrpriceB+TotStandB;
                        standB[i]=1;
                        totaltaken++;
                        Btaken++;
                        if(totaltaken==totempty)
                        {       AStand();
                                BStand();
                                CStand();                
                                Display_EndData();
                        }
                        
                        system("cls");
                        AStand();
                        BStand();
                        CStand();
        }
        else if(standB[i]==1)
        {
             printf("That seat is taken!Please re-enter your information.");
             AStand();
             BStand();
             CStand();
        }
    }
    
    int StandCSeating()
    {
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        int i,age,PatrpriceC;
        printf("\n\n\nPlease enter the");
        SetConsoleTextAttribute(hConsole,783);
        printf(" seat:\n");
        scanf("%d",&i);
        i=i-1;
        age=*ageptr;
        if(standC[i]==0)
        {               PatrpriceC=Determine_PatronPrice(age);
                        TotStandC=PatrpriceC+TotStandC;                  
                        standC[i]=1;
                        totaltaken++;
                        Ctaken++;
                        if(totaltaken==totempty)
                        {       AStand();
                                BStand();
                                CStand();                
                                Display_EndData();
                        }
                        system("cls");
                        AStand();
                        BStand();
                        CStand();
                        
        }
        else if(standC[i]==1)
        {
             printf("That seat is taken!Please re-enter your information.");
             AStand();
             BStand();
             CStand();
        }
    }
             
        
    
        
                                   
    int AStand()
    {
        int Aleft;
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        
        printf("\n");
        SetConsoleTextAttribute(hConsole,782);
        printf("\t\t\t         ~*~*~");
        SetConsoleTextAttribute(hConsole,780);
        printf(" STAND A ");
        SetConsoleTextAttribute(hConsole,782);
        printf("~*~*~");
        printf("\n");
        SetConsoleTextAttribute(hConsole,780);
        printf("\n\t\t\t-------------------------------------\n\t\t");
        for(i = 0; i < 20; i++)
        {
              if(i==5||i==10||i==15||i==20||i==25)
              {
                      
                      printf("\n\t\t\t-------------------------------------\n\t\t");
                      
              }
              
              
              
              SetConsoleTextAttribute(hConsole,780);
              printf("\t|");
              SetConsoleTextAttribute(hConsole,775);
              if(standA[i]==1)
              {
                              SetConsoleTextAttribute(hConsole,783);
                              printf(" %d ",standA[i]);
              }
              else if(standA[i]==0)
              {
                              SetConsoleTextAttribute(hConsole,775);
                              printf(" %d ",standA[i]);
              }
              SetConsoleTextAttribute(hConsole,780);
              printf("|");
              
              
        }
        printf("\n\t\t\t-------------------------------------\n");
        Aleft=20-Ataken;
        SetConsoleTextAttribute(hConsole,782);
        printf("The number of seats taken is: %d\n",Ataken);
        printf("Therefore the number of seats available is: %d\n",Aleft);
        SetConsoleTextAttribute(hConsole,775);
              
        printf("\n\n\n");
    }
        
    int BStand()
    {
        int Bleft;
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        
        printf("\n");
        SetConsoleTextAttribute(hConsole,782);
        printf("\t\t\t         ~*~*~");
        SetConsoleTextAttribute(hConsole,780);
        printf(" STAND B ");
        SetConsoleTextAttribute(hConsole,782);
        printf("~*~*~");
        printf("\n");
        SetConsoleTextAttribute(hConsole,780);
        printf("\n\t\t\t-------------------------------------\n\t\t");
        for(i = 0; i < 20; i++)
        {
              if(i==5||i==10||i==15||i==20||i==25)
              {
                      
                      printf("\n\t\t\t-------------------------------------\n\t\t");
                      
              }
              
              
              
              SetConsoleTextAttribute(hConsole,780);
              printf("\t|");
              SetConsoleTextAttribute(hConsole,775);
              if(standB[i]==1)
              {
                              SetConsoleTextAttribute(hConsole,783);
                              printf(" %d ",standB[i]);
              }
              else if(standB[i]==0)
              {
                              SetConsoleTextAttribute(hConsole,775);
                              printf(" %d ",standB[i]);
              }
              SetConsoleTextAttribute(hConsole,780);
              printf("|");
              
              
        }
        printf("\n\t\t\t-------------------------------------\n");
        Bleft=20-Btaken;
        SetConsoleTextAttribute(hConsole,782);
        printf("The number of seats taken is: %d\n",Btaken);
        printf("Therefore the number of seats available is: %d\n",Bleft);
        SetConsoleTextAttribute(hConsole,775);
              
        printf("\n\n\n");
        
    }
        
    int CStand()
    {
        int Cleft;
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        
        printf("\n");
        SetConsoleTextAttribute(hConsole,782);
        printf("\t\t\t         ~*~*~");
        SetConsoleTextAttribute(hConsole,780);
        printf(" STAND C ");
        SetConsoleTextAttribute(hConsole,782);
        printf("~*~*~");
        printf("\n");
        SetConsoleTextAttribute(hConsole,780);
        printf("\n\t\t\t-------------------------------------\n\t\t");
        for(i = 0; i < 20; i++)
        {
              if(i==5||i==10||i==15||i==20||i==25)
              {
                      
                      printf("\n\t\t\t-------------------------------------\n\t\t");
                      
              }
              
              
              
              SetConsoleTextAttribute(hConsole,780);
              printf("\t|");
              SetConsoleTextAttribute(hConsole,775);
              if(standC[i]==1)
              {
                              SetConsoleTextAttribute(hConsole,783);
                              printf(" %d ",standC[i]);
              }
              else if(standC[i]==0)
              {
                              SetConsoleTextAttribute(hConsole,775);
                              printf(" %d ",standC[i]);
              }
              SetConsoleTextAttribute(hConsole,780);
              printf("|");
              
              
        }
        printf("\n\t\t\t-------------------------------------\n");
        Cleft=20-Ctaken;
        SetConsoleTextAttribute(hConsole,782);
        printf("The number of seats taken is: %d\n",Ctaken);
        printf("Therefore the number of seats available is: %d\n",Cleft);
        SetConsoleTextAttribute(hConsole,775);      
        printf("\n\n\n");
        
        
    }
    
    
    
    
    
    
    int Determine_PatronPrice(int num1)
    {
        HANDLE  hConsole;
                hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        int Patrprice;
        if(num1< 12)
        {
                 SetConsoleTextAttribute(hConsole,775);
                 Patrprice=childcost;
                 printf("\nThe patron is classified as a child and thus pays:");
                 SetConsoleTextAttribute(hConsole,783);
                 printf(" %d\n",Patrprice);
                 Calculate_ClassRevenue(Patrprice);
                 
        }
        else if(num1>=12 && num1 <64)
        {
                 SetConsoleTextAttribute(hConsole,775);        
                 Patrprice=adultcost;
                 printf("\nThe patron is classified as an adult and thus pays:");
                 SetConsoleTextAttribute(hConsole,783);
                 printf(" %d\n",Patrprice);
                 Calculate_ClassRevenue(Patrprice);
        }
        else
        {
                 SetConsoleTextAttribute(hConsole,775);
                 Patrprice=seniorcost;
                 printf("\nThe patron is classified as a senior citizen and thus pays:");
                 SetConsoleTextAttribute(hConsole,783);
                 printf(" %d\n",Patrprice);
                 
                 Calculate_ClassRevenue(Patrprice);
                 
        } 
        getch();
        
        return Patrprice;
        
    }   
                      
    Calculate_ClassRevenue(int Patrprice)
    {
               if(Patrprice==childcost)
               {
                     totalccost=Patrprice+totalccost;
                     ccostptr=&totalccost;
               }
               else if(Patrprice==adultcost)
               {
                    totalacost=Patrprice+totalacost;
                    acostptr=&totalacost;
               }  
               else if(Patrprice==seniorcost)
               {
                    totalscost=Patrprice+totalscost;
                    scostptr=&totalscost;
               }
               
    }
    Last edited by Pr0AHP; 11-30-2009 at 10:39 PM.

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    950
    1. All functions need types and return statements.
    2. You're continuously redeclaring int i as well as other variables
    3. i=i-1;??? i--;
    4. (i==5||i==10||i==15||i==20||i==25) could be written as (!(i%5))

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help ASAP ,
    By Haytham in forum C Programming
    Replies: 3
    Last Post: 05-14-2007, 10:21 AM
  2. Need Help ASAP....
    By Maxwell in forum C++ Programming
    Replies: 16
    Last Post: 09-14-2005, 06:56 PM
  3. Strange characters in output Need Help ASAP
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2003, 05:35 PM
  4. Count_nums (need help ASAP!)
    By legacye in forum C Programming
    Replies: 6
    Last Post: 11-22-2003, 05:32 PM
  5. Help Needed Asap With Searching An Array!
    By HelpMe++ in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2003, 04:44 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21