| | |
Help with Measurement converter
Thread Solved
![]() |
•
•
Join Date: Oct 2008
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
C++ Syntax (Toggle Plain Text)
Yards = Meters * 1.094;
but i don't know how else to write it, this is my code:
C++ Syntax (Toggle Plain Text)
#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:
C++ Syntax (Toggle Plain Text)
int Meters; int Yards;
C++ 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 6:45 am.
•
•
Join Date: Nov 2008
Posts: 377
Reputation:
Solved Threads: 70
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
- 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
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






