I am a starting out 12 year old C++ programmer and I had come into a problem. Basically, It asks the user for input on what the computer will do. Instead of a simple bool where the user inputs 1 or 0, I'd like it to be more "user friendly" and execute this section of code if the user inputs this word, and this one if the user inputs this word. Also, when finished, there will be more like 5-10 different words the user would be able to input. I am on Mac OS X 10.6.8 Snow Leopard with 2 GB RAM and 2 GHz Processor. Here is my snippet of code:
#include <iostream>
using namespace std;
int main()
{
cout << "my text";
char begin;
cin >> begin;
char a;
if (begin=="a")
{
cout << "hi";
else
cout << "bye";
}
return 0;
}
So as you can see, i didn't give you the exact code to protect my code from people who rip peoples code off for a living, but what it does is it asks the user for input, and if the text the user inputs is "a", it executes this code. If the user inputs something else, it executes this other code snippet. Please help me out. Thanks!!!
edit: After i added == i got an error saying "ISO C++ forbids comparison between pointer and integer." What does this mean??????
You also might want to look into the switch statement. It does the same thing as a series of if statements, but it's a lot more readable, particularly if you have more than 3 or 4 else options.
So as you can see, i didn't give you the exact code to protect my code from people who rip peoples code off for a living,
You may not realize this, but when people 'steal' code from others it's usually not from 12 year old beginner programmers. I sincerely doubt you have anything in your code that's worth the trouble of protecting it, so you can just go right ahead and show us.