Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Weird number outputs from basic function

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Bigfatmeany   Members   

138
Like
0Likes
Like

Posted 18 February 2014 - 03:16 PM

My friend has decided to jump into C++ (which I told him wasn't the best starting language, but he insisted) as his first programming language.

He has been following these tutorials here. While he was working on functions he messaged me on skype  with a problem, he is getting a bunch of numbers from his  function. I am unable to see the problem, we could use some help with this, here is the code. 

#include <iostream>
#include <string>

using namespace std;
//Function dataType nameOffunc() {}

//function delcarations
void WelcomeMessage();
//prints a welcome message.
int calculateNum();
//Multiplies 2 intergers
//@returns product of 2 other intergers
//function in which error described occurs.

int main()
{
	int number;
	WelcomeMessage();

	cout << calculateNum << endl;
	cout << "type a number" << endl;
	cin >> number;

	return 0;
}


//function definitions
void WelcomeMessage()
{
	cout << "WELCOME" << endl;
}
int calculateNum()
{
	int x = 5;
	int y = 5;
	return (x * y);

}

what is the problem?



#2 Bigfatmeany   Members   

138
Like
0Likes
Like

Posted 18 February 2014 - 03:22 PM

Sorry for wasting the time of those who read this, I noticed the mistake almost as soon as I posted it. Can't believe I didn't notice it before that, rookie mistake on my part.



#3 mark ds   Members   

1765
Like
0Likes
Like

Posted 18 February 2014 - 03:24 PM

Well, the function returns 25. What are the "bunch of numbers" he's getting?

 

Hang on... add () to the calculateNum on line 20 - he's currently printing the address of the function, not the return value.

cout << calculateNum() << endl;

Edited by mark ds, 18 February 2014 - 03:26 PM.


#4 Bigfatmeany   Members   

138
Like
0Likes
Like

Posted 18 February 2014 - 03:27 PM

 

Well, the function returns 25. What are the "bunch of numbers" he's getting?

 

Hang on... add () the calculateNum on line 20 - he's currently printing the address of the function, not the return value.

cout << calculateNum() << endl;

Yea, Im a bit angry at myself for not noticing that he didn't add that, but we'll laugh about it soon. Atleast I'm not the only one who didn't notice it on the first time through.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.