[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

C++

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 14
Thread images: 2

File: 1416108045732.jpg (465KB, 2184x1456px) Image search: [Google]
1416108045732.jpg
465KB, 2184x1456px
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.
>>
File: 1468902156483.jpg (38KB, 680x793px) Image search: [Google]
1468902156483.jpg
38KB, 680x793px
>>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.
Thread posts: 14
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.