Thread: checking for errors..

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    checking for errors..

    hey guys, i'm writing a program that schedules appointments, cancels them, etc..
    i have 6 classes...
    appointment- checks to see if an appointment is valid
    car- holds all information about a car, reads and prints information
    date-uses various functions to convert dates
    time-uses various functions to convert times
    schedule- schedules all the appointments
    customer- keeps track of all the customer information

    anyways..when i ask a customer for a date...it needs to be written in as MM/DD/YY..and then converted... but for this particular program we are only working on the days from 01/20/03 to 01/25/03...and for time it needs to be like this XX:YY in military time...open hours are from 8-6.

    anyways i want to build in a check to make sure the user enters an appropriate date and time...

    but for some reason it only catches certain errors if you enter the inproper month or year its find the error, but for days, and time...it doesnt' find the error...

    here's the code i have right now...
    Code:
    while (cont == 'y')
    {
         cout << "What day would you like to bring the car in   
         (MM/DD/YY):  ";
         date1.ReadDate(cin);
    
         if(date1.GetMonth() == 1 && date1.GetDay() >= 20 && 
         date1.GetDay() < 26 && date1.GetYear() == 2003)
    	cont = 'n';
    
         cout << "What time would you like to bring in the car 
         (XX:YY): ";
         time1.ReadTime(cin);
    
         if((time1.GetHours() > 8 && time1.GetHours() <= 16) && 
         time1.GetMinutes() == 20 || time1.GetMinutes() == 40 || 
         time1.GetMinutes() == 00)
                   cont = 'n';
    
         system("cls");
         if(cont == 'y')
        {
              cout << "\n\n\tI'm sorry, the date or time you've entered is 
              incorrect.\n";
              system("pause");
              system("cls");
        }
    thanks for the help...somethings just a little bit off i think...

    BBNERD

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Re: checking for errors..

    The problem is you only have one variable, cont, that can catch an error. It can only catch one error, not two. Try setting up two seperate boolean variables to ensure that valid data is entered. Something like
    Code:
    bool goodDate = true, goodTime = false;
    // is better than
    char cont;
    IMO. I think that's your problem.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    Unhappy

    can you post that in a little more detail...i'm a little confused on what you mean...... I've been working on this program waaaay to long and my mind isn't working..and its due tomorrow! AHH

    thanks BBNERD

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Here's another suggestion that might be easier.
    Code:
    cout << "prompt for date";
    cin >> date;
    while(/*conditions of bad data*/)
    {
    	cout << "error message";
    	cout << "prompt for date";
    	cin >> date;
    }
    
    cout << "prompt for time";
    cin >> time;
    while(/*conditions of bad data)
    {
    	cout << "error message";
    	cout << "prompt for time";
    	cin >> time;
    }
    There you go. I often use that method to guard against bad data. Using this method, you needn't even declare another variable. I hope this helps.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    i made it into a function...i think my error checks are off..i'm so confused!!

    BBNERD

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by BODYBUILDNERD
    i made it into a function...i think my error checks are off..i'm so confused!!

    BBNERD
    If you want help from us then you have to tell us what you want to know. Post your modified code and ask a question.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM