1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ help

  1. Apr 6, 2005 #1
    I am getting an error I cannot seem to figure out. whenever I try to compile it, it says c is undeclared. I want to check a type char variable against letters of the alphabet in an if function. Maybe someone could explain what I am doing wrong.
    Code (Text):


    #include <iostream>
    #include <cctype>


    //Prototype Declaration
    void caseOne (char& vehicle);

    //Prototype Declaration
    void caseTwo (char& vehicle);

    using namespace std;

    int main()
    {
        char vehicle;                                               //vehicle type
        int hourEnter=0;                                            //Hour entered lot
        int minuteEnter=0;                                          //minute entered lot
        int hourLeft=0;                                             //Hour left lot
        int minuteLeft=0;                                           //minute left lot
        int r=0;                                                    //dummy variable
       
        cout<<endl<<endl<<endl
        <<"Please enter the type of "
        <<"vehicle you drive. "      
        <<endl<<endl                                                                                    
        <<"Please enter C for car, "
        <<"B for bus and T for truck."
        <<endl<<endl;    
       
        cin>>vehicle;                                            
       
        int islower(vehicle);
         
        if (islower=1)
        {  
            r=1;
        }
        else
            r=2;
           
        switch (r)
               {
                      case 1: caseOne (vehicle);
                              break;
                     
                      case 2: caseTwo (vehicle);
                              break;
                             
                      default: cout<<endl<<endl
                                  <<"Input error please start over.";
                              break;
               }
           
        cout<<endl<<endl
        <<"Please enter the hour, between 0 and 23,"
        <<" that you entered the lot."
        <<endl<<endl;  
       
        cin>>hourEnter;                                           //Prompt user for hour                                                                        
       
        cout<<endl<<endl
        <<"Please enter the minute, between 0 and 59, "
        <<"that you entered the lot."
        <<endl<<endl;
       
        cin>>minuteEnter;
           
        cout<<endl<<endl
        <<"Please enter the hour, between 0 "
        <<"and 23, that you left the lot."
        <<endl<<endl;
       
        cin>>hourLeft;
       
        cout<<endl<<endl
        <<"Please the minute, between 0 and 59, "
        <<"that you left the lot."
        <<endl<<endl;
       
        cin>>minuteLeft;
       
        cout<<endl<<endl                                        //program output
        <<"\tPARKING LOT CHARGE"
        <<endl<<endl
        <<"Type of vehicle:          "
        <<vehicle
        <<"\t\tTIME-IN "
        <<endl
        <<"                                              "
        <<"\t\t       "
        <<hourEnter<<minuteEnter
        <<endl<<endl<<endl;
       
     
        return 0;
    }  //main




    /*================================caseOne=======================================
         Determines type of vehicle from user input
         Pre veh contains vehicle type to be determined
         post nothing
    */

    void caseOne (char& vehicle)
    {
         char x=c;
         char y=b;
         char z=t;
         if (vehicle==x)
         {
                    vehicle=Car;
         }
         else if (vehicle==y);
         {
              vehicle=Bus;
         }
         else if (vehicle==z)
         {
              vehicle=Truck;
         }
         
         return;
    }


    /*================================caseTwo=======================================
         Determines type of vehicle from user input
         Pre veh contains vehicle type to be determined
         post nothing
    */
    void caseTwo (char$ vehicle)
    {
         if (vehicle==C)
         {
                  vehicle=Car;
         }
         else if (vehicle==B)
         {
              vehicle=Bus;
         }
         else if (vehicle==T)
         {  
             vehicle=Truck;
         }
               return;
    }
     
    Of course the program is not finished yet but I need to fix this problem before I go any futher.

    Thanks in advance

    Townsend
     
  2. jcsd
  3. Apr 6, 2005 #2
    Don't you need to put characters within single quotes in C++?

    Like this: char x = 'c';

    Otherwise, the compiler will think c is another variable.
     
  4. Apr 6, 2005 #3

    JFo

    User Avatar

    letters of the alphabet have to be in single quotes

    ie: char x = 'c';

    edit: oops, sorry nylex, didn't see you posted it already
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C++ help
  1. Need Help With C++ (Replies: 1)

  2. Help with part c? (Replies: 6)

  3. 2004 ap physics c help (Replies: 1)

Loading...