1.

Solve : convert furlongs into yards?

Answer»

This program converts furlongs into yards. 1 furlong = 220 yards
You run the program, and it ASKS you to enter a distance in furlongs. You enter a number, press enter and it spits out the equivelent distance in yards.
The conversion I USE in the funtion is 220 * sts

Say I input "9" furlongs, for the program to convert into yards...

It will spit out the number 1980..


But if I input the number 9.5 it still spits out 1980. It should spit out 2090........I would like the program to be able to output the correct VALUE...

tips, anyone?

CODE: [Select]#include <iostream>
using namespace std;
double TEST(double);

int main()
{
cout << "State a distance in furlongs:";
int variable;
cin >> variable;
int bus;
bus = TEST(variable);

cout << "The equivelent distance in yards is: " << bus;

cin.get();
cin.get();
return 0;
}

double TEST(double sts)
{
return 220 * sts;
}
your using cin to acquire a number into a variable...

What data type is that variable? "int" Does the int type support decimals?

ahh..

I believe you struck a point..

I CHANGED the int variable; and int bus; declarations to:

double variable; and double bus; (this works as int bus; also)


Now I get the right output Data types

Whole (integer) numbers (Z): int, byte, long, short

Here's a very good reference for you:
C++ Data Types

Treval



Discussion

No Comment Found