Hey guys i suck at coding and need some help anybody know why it doesnt like num?
#include <iostream>
using namespace std;
int main()
{
//variables
int message();
int num();
int code;
cout << "Please enter 1, 2, or 3: ";
cin >> code;
code = message(num);
system("pause");
return 0;
}
void message(int num)
{
if (num == 1)
cout << "Yo momma!" << endl;
else if (num == 2)
cout << "Yo Daddy!" << endl;
else
cout << "Yo Gritty Gritty Grandma!" << endl;
return 0;
}
>>59726199
>int message();
>int num();
what
>>59726199
First. Define int like this:
int num;
Second. You are asigning code to 1,2,3 (let's say user actually typed 1,2 or 3) and then you replace it's value with the function message(num).
Third. Void means it doesn't return a value. You actually want to try to return 0 in the function. If you do want to return 0, change the function to int.
Hope I didn't miss anything else
>>59726199
Wow.
What do you mean with?
>code = message(num);
You have an int and a function you didn't declare before you used it.
If you spent more time reading the book they gave you and less time shitting all over this place, you might learn something.
>>59726406
>And then you replace it's value with the function message(num)
I meant that it replaces it's value with what the function returns.
>>59726259
that's a valid way to zero-initialize (unfortunately)
>>59726406
>>59726413
>>59726424
you guys forgot to sage
>>59726199
how long does it take you to think of these bait threads?
>>59726450
Didn't know that. I actually only studied c++ in my uni for about a month some years ago.
>>59726199
>mfw I read your code
>>59726199
Grab a book or any tutorial and start all over
>>59726199
Just declare message(int num) above main()
#include <iostream>
using namespace std;
int main()
{
//variables
int message;
int num;
int code;
cout << "Please enter 1, 2, or 3: ";
cin >> code;
message(code);
return 0;
}
void message(int num)
{
if (num == 1)
cout << "Yo momma!" << endl;
else if (num == 2)
cout << "Yo Daddy!" << endl;
else
cout << "Yo Gritty Gritty Grandma!" << endl;
return 0;
}
This should work, itll print whatever the phrase that the user enters the number for
>>59727540
wait fuck i didnt even realized you tried to define message as an int Jesus Christ anon
go read a fucking textbook
http://willchil.awesomestuff.software/notes/JC_Textbooks/Starting%20Out%20with%20C++%20Early%20Objectives%20-%20Gaddis%208e.pdf
>system("pause");
Remove this line from your program and from all future programs that you write.