-
What on earth is wrong?
What on earth is wrong in this code?
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int money;
string prompt("Input how much pence without the pence sign you want to input\n"),
input;
cout << "Input how much pence without the pence sign you want to input\n";
if ( money == 50 ) {
cout << "Enter the key number of the drink you want" << endl;
cout << "1 Coke \n 2 Diet Coke \n 3 Fanta \n 4 Sprite" << endl;
}
getline( cin, input);
cout << "Please wait, your product is vending" << endl;
if ( input > 9 ) {
cout << "Invalid input" << endl;
}
else if ( money > 50 ) {
cout << "Enter a key number of the drink you want" << endl;
}
cin >> input;
}
if ( input ) {
cout << "Invalid input" << endl;
{
if ( input.length() == 2 ) {
cout << "Please wait, your product is vending" << endl;
}
else if ( input.length() < 10 ) {
cout << "Please wait, your product is vending and here is your" << input - 50 << " change" << endl;
}
return 0;
}
And the error message was.....
no match for 'operator>' in 'input > 9'
-
Well, since input is a string and 9 is an integer, is it really any surprise?
-
input is a std::string, 9 is an integer. Perhaps you want to write:
-
Input was declared as a string and you are trying to compare it to a literal int. Both types are not convertible to each other
Place 9 between double quotes.
-
Really, the > operator should be the least of your worries. Those brackets are mismatched all over the place. Code:
int main()
{
int money;
string prompt("long string that never gets used"),
input;
cout << "Input...";
if ( money == 50 ) //unlikely, since you haven't set money
{
cout << "Enter..." << endl;
cout << "1 Coke..." << endl;
}
getline( cin, input);
cout << "Please wait..." << endl;
if ( input > 9 ) {
cout << "Invalid input" << endl;
} else if ( money > 50 )
{
cout << "Enter..." << endl;
}
cin >> input;
} //here's a random bracket ending our main function
if ( input ) {
cout << "Invalid input" << endl;
{
if ( input.length() == 2 ) {
cout << "Please wait..." << endl;
}
else if ( input.length() < 10 ) {
cout << "Please wait..." << input - 50 << " change" << endl;
}
return 0;
}
//whoops, we've still got a green bracket
//and our main function to close
-
Thanks! What a stupid mistake I made!