C++ check a type char variable against letters of the alphabet

AI Thread Summary
The discussion revolves around a C++ programming issue where a user encounters an "undeclared" error for the variable 'c' while trying to check a char variable against letters of the alphabet. The user is advised to use single quotes for character literals, such as 'c', instead of treating them as undeclared variables. This correction is crucial for the compiler to recognize them as characters. Additionally, there are issues in the code related to the use of the `islower` function and the incorrect syntax in the switch-case structure. The user is encouraged to fix these errors before proceeding with further development.
Townsend
Messages
232
Reaction score
0
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:
#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
 
Physics news on Phys.org
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.
 
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
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'Minimum mass of a block'
Here we know that if block B is going to move up or just be at the verge of moving up ##Mg \sin \theta ## will act downwards and maximum static friction will act downwards ## \mu Mg \cos \theta ## Now what im confused by is how will we know " how quickly" block B reaches its maximum static friction value without any numbers, the suggested solution says that when block A is at its maximum extension, then block B will start to move up but with a certain set of values couldn't block A reach...
Thread 'Calculation of Tensile Forces in Piston-Type Water-Lifting Devices at Elevated Locations'
Figure 1 Overall Structure Diagram Figure 2: Top view of the piston when it is cylindrical A circular opening is created at a height of 5 meters above the water surface. Inside this opening is a sleeve-type piston with a cross-sectional area of 1 square meter. The piston is pulled to the right at a constant speed. The pulling force is(Figure 2): F = ρshg = 1000 × 1 × 5 × 10 = 50,000 N. Figure 3: Modifying the structure to incorporate a fixed internal piston When I modify the piston...
Back
Top