| | |
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: 392
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
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






