Hi There....

# include <iostream>
using namespace std; 
int one (int x, int y);
double two (int x, double a);

int main ()

{
    int num, x, y;
    double dec, a, first;

    cout<<"please enter two integers numbers: ";
    cin>>x>>y;

    cout<<"please enter a double number: ";
    cin>>a;

    num = one (x, y);

    dec = two (x, a);

    first = one (6, 8);

    return 0;
}

int one (int x, int y)

{
    if (x > y)
        return (x+y);

    else
        return (x-(y*2));
}

double two (int x, double a)

{
    int first;
    double z;

    cout<<z += a;

    cout<<first += x;

    if (z > first * 2)
        return z;

    else
        return (first * 2) - z;
}

Read the intro threads on how to use code tags.

One of the problems is with the output: cout<<first += x; first cout << first is evaluated, and it returns a reference to the outstream.

then this is evaluated and causes the error: cout +=x !!??

Also...

You have to initialize variables before using them in operations like adding.

try to type this

z += a;
cout<<z;
first += x;
cout<<first;

You also may run into a problem because you have the variable first declared as a double but set it equal to the function one which returns an integer:

int one (int x, int y);

double dec, a, first;

first = one (6, 8);

-D

thanx lot 4 u r reply, but my proplem is the comiler apper this error massage that ihave 2 error in this program.
(wt this two erorr mean)
C:\Documents and Settings\Welcome\Desktop\Function\Cpp3.cpp(43) : error C2676: binary '+=' : 'class std::basic_ostream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator

C:\Documents and Settings\Welcome\Desktop\Function\Cpp3.cpp(45) : error C2676: binary '+=' : 'class std::basic_ostream<char,struct std::char_traits<c
buy,

thanx lot 4 u r reply, but my proplem is the comiler apper this error massage that ihave 2 error in this program.
(wt this two erorr mean)
C:\Documents and Settings\Welcome\Desktop\Function\Cpp3.cpp(43) : error C2676: binary '+=' : 'class std::basic_ostream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator

C:\Documents and Settings\Welcome\Desktop\Function\Cpp3.cpp(45) : error C2676: binary '+=' : 'class std::basic_ostream<char,struct std::char_traits<c
buy,

The error message is telling you that there are errors on lines 43 & 45 of your program.


Your errors, on lines 43 & 45 are coming from the statements:

cout<<z += a;

cout<<first += x;

You need to initialize the 'z' and 'first' variables.

So, after declaring the variables 'z' and 'first', initialize them to 0.

ie: int x = 0 Otherwise they will contain data that you don't want them to contain.


....but this is why you're getting compiler errors:

You need to add the variables in a seperate statement, and then output the result in another statement.

Hi 2
I try 2 initlaize them, but nothing new.
any way thanx lot frnd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.