Thread: Program crashing, Need help!

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Program crashing, Need help!

    Hi, im almost finnished a program, however it keeps crashing after the user enters a value after the first choice in the menu. Heres the code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    struct details  //array for storing each structure of car details
    {
        int rego[50];  //storage for registration
        int drego[50]; //storage for the reigstration of the exiting car
        int amin[50];  //storage for the arrival in minutes
        int ahour[50]; //storage for the arrival in hours
        int dmin[50];  //storage for the departure in minutes, which is added later on by user
        int dhour[50]; //storage for the departure in hours, which is added later on by user
        //int days[50];
        int total[50];
        /*int pay=0;
        int cost;
        int j=0;*/
    }newcar;
    
        int pay=0;
        int cost;
        int j=0;
    
    int feecalc()
    {
      int timediffh; //difference in hours calculation integer 
      int timediffm; //difference in minutes calculation integer
      int min; //resultant calculation of minutes in car park
      int hour; //resultant calculation of hours in car park
      float fee; //the initial flat fee of $2
      float extraa; //float for the subtraction of 3 from the number of hours
      float extrab; //float for the multiplication of the $1.5 per hour
      float extrac; //float for the rounding of minutes, adding an aditional hour
      float total; //grand total of what is charged to that car
      float minutecharge; //rounding minutes off to the next hour
      
      timediffh = newcar.dhour[pay] - newcar.ahour[pay];
      timediffm = newcar.dmin[pay] - newcar.amin[pay];
      if(timediffm < 0) //if the number of arrival time has a higher value than the departure time, then add 60
                   {
                         min = timediffm +60;
                         hour = timediffh - 1;
                   }
      else
                   {
                         min = newcar.dmin[pay] - newcar.amin[pay]; //other wise continue on with the original calculation
                         hour = newcar.dhour[pay] - newcar.ahour[pay];
                   }
    
      if(hour < 3)
                   {
                         fee = 2.00;
                         newcar.total[pay] = fee;
                   }
      else
                   {
                         fee = 2.00;
                         extraa = hour - 3;
                         extrab = extraa*1.5;
                         newcar.total[pay] = fee + extrab;
                   }
      if ((newcar.dmin > 0) && (hour >= 3))
                   {
                         extrac = +1.5;
                         newcar.total[pay] = fee + extrab + extrac;
                   }
      if (total >= 10)
                   {
                         newcar.total[pay] = 10;
                   }
      printf("Number of hours in car park:%ihours %iminutes\n",hour,min);
      printf("Cost for the number of hours is:$%.2f\n",newcar.total[pay]);
    }
    
    int entry()
    {
      int plate, face;
      printf("###Car Arrival###\n");
      printf("Please Enter a 4 Number Registration Plate:\n");
      scanf("%i", plate);
      for(face = 0;face < 51; face ++)
              {
     if(plate == newcar.rego[j])
                   {
                         printf("you suck");
                         entry();
                   }
    }
    newcar.rego[j] = plate;
    if(newcar.rego[j] < 10000)
                   {
                         printf("WRONG");
                   }
    newcar.rego[j] = 0;
    printf("Please Enter The Time of Car Arrival in hours(24 Hour Time Used):\n");
    scanf("%i", &newcar.ahour[j]);
    if(newcar.ahour[j] > 24)
                   {
                         printf("Fail");
                         entry();
                   } 
    printf("Please Enter The Time of Car Arrival in Minutes:\n");  
    scanf("%i", &newcar.amin[j]);
    if (newcar.amin[j] > 60)
                   {
                         printf("Fail");
                         entry();
                   }
    j++;
    main();
    }
    
    int dept()
    {
      int nope;
      int exitplate;
      printf("Please Enter a 4 Number Registration Plate number:\n");
      scanf("%i", &exitplate);
      for(nope = 0; nope < 51; nope++)
           {
              if(exitplate == newcar.rego[nope])
              {   
                  newcar.drego[pay] = exitplate;
                  if(exitplate < 10000)
              {
                  printf("your gay");
                  dept();
              }         
      printf("Please Enter The Time of Car Departure in hours(24 Hour Time Used):\n");
      scanf("%i", &newcar.dhour[pay]);
      if(newcar.dhour[pay] > 24)
              {
                  printf("EFG");
              }
      if(newcar.dhour[pay] < newcar.ahour[nope])
              {
                  printf("Error, cannot leave before entering");
                  dept();
              }
      printf("Please Enter The Time of Car Departure in Minutes:\n");
      scanf("%i", &newcar.dmin[pay]);
      if(newcar.dmin[pay] > 60)
              {
                  printf("Fail");
                  dept();
              }
    }}}
                               
    int main()
    {
      int user;
    
      printf("1. Car Arrival\n");
      printf("2. Car Departure\n");
      printf("3. Print Out of Daily Data\n");
      printf("4. Quit Program\n");
      scanf("%i", &user);
    
      switch(user)
    {
      {
      case 1://Writes to car structure 
            entry(); 
           
    
        
      case 2:
            dept();
            feecalc();
      case 3:
    
           printf("Bull........\n");
    
         return main();
         }
      }}

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    In entry you should have
    scanf("&#37;d", &plate)
    you forgot the &

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    2
    thanks, i would not have spotted that.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do not call main in your code. Use loops. Main should be called once and once only. It's special.
    And fix your indentation, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM