Hi
Please check the code given below. The following are the errors I get. I don't get the reason for the bold errors.
Code:
reference to 'distance' is ambiguous|
candidates are: struct distance|
template<class _InputIterator> typename std::iterator_traits::difference_type std::distance(_InputIterator, _InputIterator)|
reference to 'distance' is ambiguous|
candidates are: struct distance|
template<class _InputIterator> typename std::iterator_traits::difference_type std::distance(_InputIterator, _InputIterator)|
expected ';' before 'd1'|
'd1' was not declared in this scope|
expected '}' before 'else'|
expected unqualified-id before 'return'|
expected constructor, destructor, or type conversion before '(' token|
expected declaration before '}' token|
Edit: I have corrected one of the bold errors - the one with the else block.
Code:
/* Define distance structure, int feet, float inches. Read two distances. Add them to find sum */
#include <iostream>
#include <cstdlib>
using namespace std;
////////////////////////////////////////////////////
struct distance
{ int feet; int inches; };
////////////////////////////////////////////////////
int main()
{
distance d1; int x, y, z;
cout<<"enter feet: "; cin>>d1.feet;
cout<<"enter inches: "; cin>>d1.inches;
{
if (d1.inches<12)
{
cout << "the distance is: " << d1.feet << "." <<d1.inches << endl;
}
else
{
x = d1.inches % 12;
y = d1.inches - x;
z = y/12;
d1.feet += z;
cout << "the distance is: " << d1.feet << "." << x << endl;
}
}
return 0;
system("pause");
}