So I'm very new to C++ and I taking a class on intro to programming and this is one of my assignments and I'm having a problem with the last part of the code where i'm trying to be able to get the ASCII value for anything like all Upper case letters and Lower, and numbers 0 - 9. However my InputAnswer isn't grabing anything else but the specified variables in numberInput (so 0 and 9), UcapInputX (just A) but not LcapInputX. Does anyone have any idea how I could fix it? Also I don't really get if else statements. The more simple the better, and sorry if my code looks a little gross.
Cheers,
Edit: sorry first post don't really know what to do when posting, hopefully i did what you asked. also I cut it down to the one part which isn't working, everything else is working fine now thanks.
[Code]
<iostream>
<iomanip>
<time.h>
/* Idon't understand if else statements.*/
cout << "\n";
cout<<"1. Enter any character in Lower case, Upper case or numbers between 0 - 9 then we will show you its ASCII value: ";
cin>> InputAnswer;
if(InputAnswer == numberInput){
cout<< "The ASCII value of " << numberInput << " is equal to " << (int)numberInput << "." << endl;
}
else if(InputAnswer == UcapInputX){
cout<< "You entered " << UcapInputX << " which has a ASCII value of " << (int)UcapInputX << "." << endl;
cout<< " " << UcapInputX << "is part of the Upper case group. "<< endl;
}
else if(InputAnswer == LcapInputX){
cout<< "The ASCII value of " << LcapInputX << " is equal to " << (int)LcapInputX << "." << endl;
}
char nInput = '0';
char Ucap = 'A';
char Lcap = 'a';
cout<< "Enter either a upper case letter, a lower case letter, or a number between 0-9: ";
cin>> nInput, Ucap, Lcap;
if(nInput){
cout<<"You entered " << nInput << " which has a ASCII value of " << (int)nInput << ". " <<endl;
cout<< nInput << " belongs in the Numbers Group."<<endl;
}elseif(Ucap){
cout<<"You entered " << Ucap << " which has a ASCII value of " << (int)Ucap << ". " <<endl;
cout<< Ucap << " belongs in the Upper Case Group."<<endl;
}elseif(Lcap){
cout<<"You entered " << Lcap << " which has a ASCII value of " << (int)Lcap << ". " <<endl;
cout<< Lcap << " belongs in the Lower Case Group."<<endl;
}
> cin>> nInput, Ucap, Lcap;
I would suggest you print out those 3 variables to see what you typed in.
Your input doesn't do what you expect it to.
As with your if(UcapInput == 'A'|| 'B'|| 'C') thing, you can write a lot of things which are syntactically valid (they compile), but the meaning (what it actually does) is a lot different to what you expect.