| | |
Help with Measurement converter
Please support our C++ advertiser: Intel Parallel Studio Home
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: 397
Reputation:
Solved Threads: 72
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
Views: 442 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






