plzz help me with this program

#include<iostream.h>
#include<conio.h>
int sum(int s);
int sum(int x);
int sum(int j,int k);
float sum(float p,int q);
float sum(float y,float z);
void main()
{
cout<<sum(0)<<"\n";
cout<<sum(3)<<"\n";
cout<<sum(6,7)<<"\n";
cout<<sum(5.5,8)<<"\n";
cout<<sum(4.9,3.5)<<"\n";
getch();
}

int sum(int s)
{
return s;
}

int sum(int x)
{
return x;
}

int sum(int j,int k)
{
return (j+k);
}

float sum(float p,int q)
{
return (p+q);
}

float sum(float y,float z)
{
return (y+z);
}

Recommended Answers

All 4 Replies

Help you with what? Is there a part that isn't working right? Are you getting compiler errors?

These functions are redundant, pick one and use it.

int sum(int s)
{
    return s;
}
int sum(int x)
{
    return x;
}

Hello,

There are a few errors in your code (hope I'm not wrong):

  1. You define the same method (with one parameter/int) twice: lines 18 and 23
  2. At lines 33 and 38 your formal parameters are floats but you call the function using doubles - you can fix this by changing floats to doubles ( ex: 5.5 to 5.5f ) or simply change the parameter's type from the methods's header.

At lines 33 and 38 your formal parameters are floats but you call the function using doubles - you can fix this by changing floats to doubles ( ex: 5.5 to 5.5f ) or simply change the parameter's type from the methods's header.

Doubles are automatically converted to floats when needed, and vice-versa. This is not necessary.

it is function / method overloading.

operator overloading is quiet a different stuff. ))

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.