As a beginner in c++ I tried out a simple program on function overloading.While compiling I received the following warnings:
1.'=' : conversion from 'int' to 'float', possible loss of data
2. 'argument' : conversion from 'int' to 'float', possible loss of data
3. 'argument' : conversion from 'int' to 'float', possible loss of data
4. '=' : conversion from 'int' to 'float', possible loss of data
5. '=' : conversion from 'double' to 'int', possible loss of data
6. '=' : conversion from 'double' to 'int', possible loss of data
After running what ever input I give I get Zero as output in every case.
My program:
#include "stdafx.h"
#include <iostream>
using namespace std;
int circle(int a);
int rectangle(int a,int b);
int triangle(float a,float b);
int main()
{
int area1,a,b;
float area3,area2;
std::cout<<"Enter the radius of the circle"<<endl;
std::cin>>a;
area1= circle(a);
std::cout<<area1<<endl;
std::cout<<"Enter the dimensions of the rectangle"<<endl;
std::cin>>a>>b;
area2= rectangle(a,b);
std::cout<<area2<<endl;
std::cout<<"Enter the base and height of the triangle"<<endl;
std::cin>>a>>b;
area3= triangle(a,b);
std::cout<<area3<<endl;
}
int circle(int a)
{
int area1;
area1=3.14*a*a;
return (0);
}
int rectangle(int a,int b)
{
int area2;
area2=a*b;
return (0);
}
int triangle(float a,float b)
{
int area3;
area3=.5*a*b;
return (0);
}
The output should be:
Enter the radius of the circle 2
6
Enter the dimensions of the rectangle 2 4
8
Enter height and base of triangle 2.5 10
25
Instead the output comes:
Enter the radius of the circle 2
0
Enter the dimensions of the rectangle 2 3
0
Enter the base and height of the triangle 2.5 10
0
Tags: