Troubles with a program
Helpless newbie question:
Okay, so I get a compiler and I''m bored.. so I decide to try it out by making some cheesy little program who''s outcome should go like this:
A or B?
A
Okay, A.
*OR*
A or B?
B
Okay, B.
Simple concept, right?? Alright, now here''s the actual problem:
This probably isn''t the easiest way to program this but I''m a newbie and this is all I could think up at the moment. I need to declare an int for a so that when the computer reads the input it will recognize it and reply. Whenever I try to declare: int a.. the compiler comes back with some comment about a const char*.. so I re-declare a as: char* a.
Now the error goes away and all compiles fine.. but whenever I try to run the program I get:
"A or B?"
and when I try to process my input, the program crashes!
So I''m guessing that the problem had something to do with the whole char/int error.. but my other hunch is that I could be miss-using cin.
Wanna help me out??
// Chimaera
Tell us what compiler you have, and just copy paste your whole program into another post k? I think that will be the easiest way for us to figure out what''s wrong on something this simple.
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
In the future, if you include the source code it would make things easier. (Then again, this doesn't exactly constitute a major program either )
After all that, you may want to get some beginners books on programming. The local library is sure to have some.
Micah
Edit: One of these days I'll remember the tag's source NOT code
Edited by - MicahJon on October 12, 2000 6:24:56 PM
#include <iostream>int main(){ char MyChar; std::cout << "Enter A or B please" << std::endl; std::cin >> MyChar; if(MyChar == 'A' || MyChar == 'a' || MyChar == 'B' || MyChar == 'b') { std::cout << "You entered " << MyChar << std::endl; } else { std::cout << "You can't follow simple directions?" << std::endl; } return 0;}
After all that, you may want to get some beginners books on programming. The local library is sure to have some.
Micah
Edit: One of these days I'll remember the tag's source NOT code
Edited by - MicahJon on October 12, 2000 6:24:56 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement