Having trouble multiplying two variables

The program is supposed to take the users input in "furlongs" than convert that to yards. One furlong is 220 yards... so this is what i have so far but i keep getting an error about not using the right operator in the following code:

#include <iostream>
#include <string>

int main()
{
using namespace std;

string furlongs;
int yards;

yards = 220;




cout << "How many 'furlongs' did you run?" << endl;
getline(cin, furlongs);
//yards = furlongs * 220;
//yards = (furlongs * yards);
cout << "Damn dude you ran " << yards << " yards!!" << endl;
cout << "Congrats!!";


return 0;
}

the commented code are the attempts i have made...any help appriciated thx.
Morning,

Firstly, we only need to deal in number variables here - whole numbers and so int variables should be fine for all.

Simplest (and so best at this stage) is to create two int variables only if you only want to convert one way:-
1
2
int furlongs;
int yard_result;


then cin >> furlongs;

then do the maths:

yard_result=furlongs*220;

All that then remaing is to output the result

cout << "Holy shit, that was " << yard_result << "yards dude!!!!!" << endl;

Hope this helps.

Dan
i changed my program with your suggestions to the following:

#include <iostream>


int main()
{
using namespace std;

int furlongs;
int yard_result;

cout << "How many 'furlongs' did you run?" << endl;
cin >> furlongs;
yard_result = furlongs * 220;
cout << "Damn dude you ran " << yard_result << " yards!!" << endl;
cout << "Congrats!!";


return 0;
}

the program runs however the math seems off and it does not print how may yards you ran

[Session started at 2010-05-15 23:44:05 -0400.]
How many 'furlongs' did you run?
3
2203
The Debugger has exited with status 0.

any suggestions? I am using xcode for mac
Reinstall XCode. Your copy of GCC 4.2.1 is insane if that is really the output you're getting.

-Albatross
Topic archived. No new replies allowed.