hey
I'm new to c++ and i've done a few tutorials, but i find i learn better by experimenting with stuff, so im trying to add a few commands(from a website i googled) onto the stuff i did in the tutorial, but one of the lines from the tutorial doesn't work now. if someones able to help me, that would be great. its something really simple probably, and if someone wants to tell me whats wrong ill copy/paste it all in here or whatever.
I and probably many other members of this forum will be more than willing to help you out if you paste the code along with any errors your compiler may have spitted out.
int main()
{
printf("HEY MACHITA, WHATS UP?\n");
cout<< "what NiNe ThOuSaNd??\n";
printf("ha ha ha \nit took forever to get it to make new lines");
cout<< " but i... \nFIGURED IT OUT";
cout<< "\nand now, something completely different";
}
int number()
{
cout<< "Please enter a number: ";
cin>> number;
cin.ignore();
cout<<"You entered this number: "<< number <<"\n";
if (number==a) {cout<< "\nthats my lucky number!";}
cin.get ();
}
thats not all of it, i got rid of some of it and im going to try putting it in differently. im trying to make this in a way that depending on the number entered, a different message is shown, but the line "cin>> number;" isnt working as it did in the tutorial. if im doing everything wrong, tell me, and ill take another look at the tutorials again...
a and number do not appear to be defined as variables. In fact, a doesn't even appear to be defined...
EDIT: Details:
When I compiled this, my compiler spat these errors:
a is not declared in this scope
Ambiguous overload for operator>> in std::cin >> number
In short, you need to declare a and number as variables, and rename your function to something else.
And if you declared int a after your defined your int number() then that won't work. I'm not 100% sure what you mean, but if you declared a after you defined your function, that's not going to work. You have to declare things before they are used.
what i saw as problem is that main needs a return type like 0 also the function number
and you have declared number as function and also as variable and use it as test !!
confusing the compiler wether it's a call to function or variable
and try to sperate the \n from the text ur outprinting
I'm using GCC, but it has a front-end, known as XCode. Virtually all sane compilers would give the error... what are you using as an IDE and what are you using as a compiler?
Also, regarding the variable, I don't think you can do that. Try placing the variables before int number().
another question, i tried googleing this but got nothing, is there a command of some sort that jumps back and re-reads a line X number of times? thanks in advnce