Please find the error , program to add meter and centimeter?

Home » Programming & Design » Please find the error , program to add meter and centimeter?
Programming & Design No Comments

#include<iostream>
using namespace std;
class distance {
int m,cm;
public :
void get();
void show();
friend distance add(distance d1,distance d2);
};
void distance::get()
{
cout << "Enter the value in meter and centimeter";
cin >>m>>cm;
}
void distance

#include<iostream>
using namespace std;
class distance {
int m,cm;
public :
void get();
void show();
friend distance add(distance d1,distance d2);
};
void distance::get()
{
cout << "Enter the value in meter and centimeter";
cin >>m>>cm;
}
void distance ::show()
{
cout << "Entered value is " << " " << m << "meter" <<"and" << " " << cm << "centimeter" ;
}
distance add(distance d1,distance d2)
{
distance d3;
d3.m=d1.m+d2.m;
d3.cm=d1.cm+d2.cm;
if(d3.cm >=100)
{
d3.m=d1.m+d2.cm%100;
d3.cm=d3.cm%100;
}
return (d3);
}
int main (){
distance m1,m2,m3;
m1.get();
m2.get();
m1.show();
m2.show();
m3=add(m1,m2);
m3.show();
return 0;

}

Other answer:

EddieJ:
You didn't mention what error message you got.

It seems that "distance" might be something that is built-in, so change the name of your class to something else.

takeabyte:
"Find the error"
"Find the compiler"
"Find the rest of the code, too"
Hilarious
Duncan:
Found…

Untitled.cpp:19:1: error: reference to 'distance' is ambiguous
distance add(distance d1,distance d2)
^
Untitled.cpp:3:7: note: candidate found by name lookup is 'distance'
class distance {
^
/Applications/Xcode.app/Contents/Develo… note: candidate found by name lookup is 'std::__1::distance'
distance(_InputIter __first, _InputIter __last)
^
Untitled.cpp:19:14: error: reference to 'distance' is ambiguous
distance add(distance d1,distance d2)
^
Untitled.cpp:3:7: note: candidate found by name lookup is 'distance'
class distance {
^
/Applications/Xcode.app/Contents/Develo… note: candidate found by name lookup is 'std::__1::distance'
distance(_InputIter __first, _InputIter __last)
^
Untitled.cpp:19:26: error: reference to 'distance' is ambiguous
distance add(distance d1,distance d2)
^
Untitled.cpp:3:7: note: candidate found by name lookup is 'distance'
class distance {
^
/Applications/Xcode.app/Contents/Develo… note: candidate found by name lookup is 'std::__1::distance'
distance(_InputIter __first, _InputIter __last)
^
Untitled.cpp:21:1: error: reference to 'distance' is ambiguous
distance d3;
^
Untitled.cpp:3:7: note: candidate found by name lookup is 'distance'
class distance {
^
/Applications/Xcode.app/Contents/Develo… note: candidate found by name lookup is 'std::__1::distance'
distance(_InputIter __first, _InputIter __last)
^
Untitled.cpp:22:1: error: use of undeclared identifier 'd3'
d3.m=d1.m+d2.m;
^
Untitled.cpp:23:1: error: use of undeclared identifier 'd3'
d3.cm=d1.cm+d2.cm;
^
Untitled.cpp:24:4: error: use of undeclared identifier 'd3'
if(d3.cm >=100)
^
Untitled.cpp:26:1: error: use of undeclared identifier 'd3'
d3.m=d1.m+d2.cm%100;
^
Untitled.cpp:27:1: error: use of undeclared identifier 'd3'
d3.cm=d3.cm%100;
^
Untitled.cpp:27:7: error: use of undeclared identifier 'd3'
d3.cm=d3.cm%100;
^
Untitled.cpp:29:9: error: use of undeclared identifier 'd3'
return (d3);
^
Untitled.cpp:32:1: error: reference to 'distance' is ambiguous
distance m1,m2,m3;
^
Untitled.cpp:3:7: note: candidate found by name lookup is 'distance'
class distance {
^
/Applications/Xcode.app/Contents/Develo… note: candidate found by name lookup is 'std::__1::distance'
distance(_InputIter __first, _InputIter __last)
^
Untitled.cpp:33:1: error: use of undeclared identifier 'm1'
m1.get();
^
Untitled.cpp:34:1: error: use of undeclared identifier 'm2'
m2.get();
^
Untitled.cpp:35:1: error: use of undeclared identifier 'm1'
m1.show();
^
Untitled.cpp:36:1: error: use of undeclared identifier 'm2'
m2.show();
^
Untitled.cpp:37:1: error: use of undeclared identifier 'm3'
m3=add(m1,m2);
^
Untitled.cpp:37:8: error: use of undeclared identifier 'm1'
m3=add(m1,m2);
^
Untitled.cpp:37:11: error: use of undeclared identifier 'm2'
m3=add(m1,m2);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

LEAVE A COMMENT