another question

+1 Ronghui Zhan · February 7, 2015
why the following is wrong? 

#include <iostream>

using namespace std;

int age(int x, int y){
     int sum = x + y;
     return sum;
     cout << sum << endl;
}
int main (){
     age(32,54);
     return 0;
}

why can't we put cout under the function age? i tried it and there is nothing i got on screen. 

Post a Reply

Replies

Oldest  Newest  Rating
0 Cardinal Coog · February 8, 2015
Either remove the line "return sum;" or put the statement "cout << sum << endl;" before the "return sum;" This printed out "86".

#include <iostream>

using namespace std;

int age(int x, int y){
int sum = x + y;
cout << sum << endl;
return sum;

}
int main (){
age(32,54);
return 0;
}
0 Ronghui Zhan · February 8, 2015
i have no idea.....
  • 1

C++

106,985 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator