1,105,633 Community Members

[Error] reference to 'distanc

Member Avatar
soche123
Light Poster
41 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

compiler is showing this error but I don't know where I went wrong with my simple structure program.

#include <iostream>
#include <conio.h>
using namespace std;
#include<iostream>
#include<conio.h>
using namespace std;
struct distance                //structure 
{
    int foot;
    float inches;
}; 
int main()
{

distance a,b;
distance c={3,6.34};
cout<<"Enter feet and inches of distance a"<<endl;
cin>>a.foot<<a.inches<<endl;
b.inches=c.inches+a.inches;
b.foot=c.foot+a.foott;
cout<<"distance a: "<<a.foott<<a.inches<<endl;
cout<<"distance b: "<<b.foott<<b.inches<<endl;
cout<<"distance c: "<<c.foott<<c.inches<<endl;
getche();
return 0;
}
Member Avatar
rubberman
Industrious Poster
4,006 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 505 [?]
Skill Endorsements: 87 [?]
 
0
 

Plese post the entire compiler error output. However, line 18 is wrong. Instead of cin>>a.foot<<a.inches<<endl; try cin>>a.foot>>a.inches;

Member Avatar
deceptikon
Eternally Awesome
4,700 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 690 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

distance is the name of a function in the standard library, use it for something else at your own risk.

Check your spelling and choice of operators as well.

Member Avatar
soche123
Light Poster
41 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

it stiil says [Error] reference to 'distance' is ambiguous even after I've corrected the 18th line..

Member Avatar
tinstaafl
Postaholic
2,014 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

Like was mentioned you've used a keyword as a custom type. Line 18 has nothing to do with that error. Change the name of your struct.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article