OT: C++ Question

Karl Larsen klarsen1 at gmail.com
Thu Mar 12 21:06:33 UTC 2009


karl at cheap-laptop:~/cplus$ more ex75.c
//*********************************************************************
// Program Convert: this program converts feet and inches to centimeters
// using 1 inch = 2.54 CM.
//***********************************************************************

#include <iostream>
using namespace std;

// Named constants
const double conversion = 2.54;
const int inchesPerFoot = 12;

int main()
{
// declare variables
int feet;
int inches;
int totalInches;
double centimeter;

// Statements: Step 1 - Step 7
cout<<"Enter two integers, one for feet, "
<<" one for inches: "; //Step1
(line 24) cin<<feet<<inches; //Step2
cout<<endl;
cout<<" The numbers you entered are "<<feet
<<" for feet "<<"and" <<inches
<<" for inches. "<<endl; //Step3

totalInches = inchesPerFoot * feet + inches; //Step4
cout<<endl;
cout<<" The total number of inches = "
<<totalInches<<endl; //Step5
centimeter = conversion * totalInches; //Step6
cout<<" The number of centimeters = "
<<centimeter<<endl; //Step7
return 0;
}



karl at cheap-laptop:~/cplus$ g++ ex75.c
ex75.c: In function ‘int main()’:
ex75.c:24: error: no match for ‘operator<<’ in ‘std::cin << feet’
karl at cheap-laptop:~/cplus$



As you can see the little c++ example from the book does not compile. I 
added the (line 24) so you readers can see what line the g++ compiler 
see's an error. I simply can't see the error and so need some help.

Your welcome to try it on your Linux and I hope you do.

73 Karl





More information about the ubuntu-users mailing list