invalid operand errors galore

Hi all, i'm new here and new to programming. Searched forums but for some reason still can't find the solution to this errors I'm getting:
error: invalid operands of types ‘std::ostream’ and ‘const char [39]’ to binary ‘operator<<’


Heres the code:

#include <iostream>
using namespace std;

int main()

{

int input, inches, feet, yards, x;

x=5280;

cout << "Enter a number in inches:";
cin << input;

//calculations here
input = yards/432;
yards = input%432;
feet = input/12;
yards = input%12;

if (input<=x)

{ cout << "You entered:" cout << input;
cout << "There are"; cout << inches; cout << "inches,";
cout << feet; cout << "feet,";
cout << yards; cout << "yards.\n";
}

else

{
cout << "Error: You entered a number too small!" << endl;
}
// cout.setf(ios::fixed);
// cout.setf(ios::showpoint);
// cout.precision(2);

return 0;
}
You have several errors.

Instead of

cin << input;

shall be

cin >> input;

This statement has no any sense

input = yards/432;

because 1) variable yards is not initialized 2) you are overwriting just entered value.

Here

cout << "You entered:" cout << input;
you forgot to place a semicolon to separate two statements.
Last edited on
thank you vlad, I appreciate it. I fixed some things, however still getting the operan errors. Any advice?

#include <iostream>
using namespace std;

int main()

{

int input,inches,feet,yards,x;

x=5280;

cout << "Enter a number in inches:";
cin >> input;


inches = yards/432;
yards = input%432;
feet = input/12;
yards = input%12;

if (input<=x)

{ cout << "You entered:"; cout << input;
cout << "There are"; cout << inches; cout << "inches,";
cout << feet; cout << "feet,";
cout << yards; cout << "yards.\n";
}

else

{
cout << "Error: You entered a number too small!" << endl;
}
// cout.setf(ios::fixed);
// cout.setf(ios::showpoint);
// cout.precision(2);

return 0;
}
You are using still uninitialized variable yards

inches = yards/432;

And next time specify the error mesaage and the statement where the error occured.
Vlad: here is the error message:
a.cpp: In function ‘int main()’:
a.cpp:53:10: error: invalid operands of types ‘std::ostream’ and ‘const char [26]’ to binary ‘operator<<’
a.cpp:65:11: error: invalid operands of types ‘std::ostream’ and ‘const char [13]’ to binary ‘operator<<’
a.cpp:66:10: error: invalid operands of types ‘std::ostream’ and ‘const char [10]’ to binary ‘operator<<’
a.cpp:66:47: error: invalid operands of types ‘std::ostream’ and ‘const char [8]’ to binary ‘operator<<’
a.cpp:67:24: error: invalid operands of types ‘std::ostream’ and ‘const char [6]’ to binary ‘operator<<’
a.cpp:68:25: error: invalid operands of types ‘std::ostream’ and ‘const char [8]’ to binary ‘operator<<’
a.cpp:76:10: error: invalid operands of types ‘std::ostream’ and ‘const char [39]’ to binary ‘operator<<’

btw i changed inches = yards/432 to inches = input;
They are very strange errors. They should not be.

Try to include headers <string> and <iomanip>
Topic archived. No new replies allowed.