ok im trying to make a calculator but i dont know how to use say
type a when u want to add
and type b when u want to subtract i want to surprise my parents but i need to know this
ok im trying to make a calculator but i dont know how to use say
type a when u want to add
and type b when u want to subtract i want to surprise my parents but i need to know this
Use a char variable. Read the user's input into the char variable. Then use switch (variable) and case 'a', case 's', etc. Make sure to break after each case. Also be careful about the fact that 'a' and 'A' are different characters, so you will have to handle both if you want to handle both.
to handle the probs of 'a' and 'A', just put it like this:
case 'a':
case 'A':
to handle the probs of 'a' and 'A', just put it like this:
etc...Code:case 'a': case 'A': statements goes here; break; case 'b': case 'B': statements goes here; break;
um i got confused at a does anyone have a short example of one maybe something easy like you press enter it says hello then it asks if you want to change it to something else like hey but if it takes more than 6 minutes just forget about it i dont know much about coding so wut i think takes seconds could take hours
hope this helpsCode:char x; cout <<"Hello world!" <<endl; cin >>x; switch (x){ case 'a': // Do addition break; case 'A': // Do addition break; case 'd': // Do division break; case 'D': // Do division break; default: cout <<"Invalid value" <<endl; }
Last edited by RealityFusion; 09-22-2005 at 02:02 AM.
Knowledge is power and I want it all
-0RealityFusion0-
Use char instead of int so that the letter will be read in properly.
as long as it gets the job done then its all good.
If you are referring to char vs. int, then int would not get the job done in this case. The code wouldn't work.
In general, something that gets the job done for now isn't all good if there is a more correct solution that will cause fewer problems in the future.
lol omgz really???? that is so c00l!1!!!!!!
can char store alphanumeric or just characters?
im getting majorly confused im gonna make this a poll to see whether int or char is better im hearing different results
edit never mind i cant make a poll
A char variable really just holds a small integral number. It is generally used to refer to characters from a particular character set, like ASCII. If you look at an ASCII chart, you will see the characters that can be held by a char by most platforms using the ASCII character set (which yours almost certainly is). In this character means something different than the just alphabetic letters like A-Z. Other characters include each digit ('0', '1', '2', ... '9' are all characters), lots of special characters (e.g. a newline '\n', tab '\t' and space ' '), and other non-printable characters.
>> im getting majorly confused im gonna make this a poll to see whether int or char is better im hearing different results
No need to make a poll. If you don't believe me, just try the code yourself. It won't work with int.
no i believe you but i also believe everyone else but how would i use char
and i dont mean to be a dirty doopy doop but i use dev
Last edited by lilhawk2892; 09-21-2005 at 07:11 PM.