blackpepper February 2016

I can't understand why my output is 1,1 how can I change it to "type name" and "parameters"? TIA

I'm just new at c++ and I'm reading about functions but now I'm trying to use string but I really can't understand it. how can I show the "type name" and "parameters" in my output? here's my code:

#include <iostream>
using namespace std;

string f1 (string a)
{
    string b;
    b = " type name ";
    return (b);
}

string f2 (string c)
{
    string d;
    d = " parameters ";
    return (d);
}

int main ()
{
    string x,y;
    x = f1(" type name ");
    y = f2(" parameters ");
    cout<<"Functions is a group of statements that executed"<<endl;
    cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
    cout<<"and a statement. It can be called to some some point of the program."<<endl;

    return 0;
   }

Answers


Humam Helfawi February 2016

Change this :

cout<<"when it is called. It is consist of"<< f1 <<","<< f2 <<endl;

To this:

cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;

However, you have redundancy in your code.


evk1206 February 2016

What are you trying to do ,

string f1 (string a)
string f2 (string c)

accepts a string but you not doing anything withit, in the main you are calling the function with the string you never used internally.

Are you trying to use,

string f1 ()
string f2 ()

and use this

cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;

you are trying to print the strings right not the functions


TartanLlama February 2016

cout<<"when it is called. It is consist of"<< f1 <<","<< f2 <<endl;

f1 and f2 are functions. You don't want to output the functions, you want to output the result of calling the functions.

x = f1(" type name ");
y = f2(" parameters ");

You have stored the result of the calls in x and y, so use those.

cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
//                                            ^         ^

Post Status

Asked in February 2016
Viewed 2,445 times
Voted 10
Answered 3 times

Search




Leave an answer