Help with Measurement converter
Please support our C++ advertiser: Programming Forums
Thread Solved
![]() |
•
•
Posts: 5
Reputation:
Solved Threads: 0
Hey I am trying to teach myself C++ and i am having trouble with a measurement converter I am pretty sure my problem is in the line
but i don't know how else to write it, this is my code:
Your help would be greatly appreciated
Yards = Meters * 1.094;
but i don't know how else to write it, this is my code:
#include <iostream>
namespace std;
int main()
{
cout << "welcome to my measurement converter.";
cout << "This converter will convert meters to yards.\n";
cout << "Enter the number of meters.\n";
int Meters;
int Yards;
cin >> Meters;
Yards = Meters * 1.094;
cout << Meters << " meters is equal to " << Yards << " yards";
return 0;
}Your help would be greatly appreciated
2 things.
Change :
then change:
to:
Int can only be integer values So: 1, 4 , 300, 5632 etc etc.
But you need some digits after the comma, so you need the double data-type
Change :
namespace std; to using namespace std; . Your code shouldn't compile without changing it.then change:
cplusplus Syntax (Toggle Plain Text)
int Meters; int Yards;
cplusplus Syntax (Toggle Plain Text)
double Meters; double Yards;
Int can only be integer values So: 1, 4 , 300, 5632 etc etc.
But you need some digits after the comma, so you need the double data-type
Last edited by niek_e : Nov 25th, 2008 at 5:45 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
•
•
Posts: 302
Reputation:
Solved Threads: 56
The mistake is that you are using integers (the set 0,1,2,3 and -1 etc)
to represent floating point number.
write
instead of the two int declarations.
to represent floating point number.
int a=2*1.2;
gives sets a to 2.write
c++ Syntax (Toggle Plain Text)
double Meters; double Yards;
![]() |
Similar Threads
Other Threads in the C++ Forum
- Projects for the Beginner (Python)
- whats the difference btw memory,warp,cpu and gpu clocks (Motherboards, CPUs and RAM)
Other Threads in the C++ Forum
- Previous Thread: Need help with class constructor..
- Next Thread: How to include .lib files
•
•
•
•
Views: 344 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode