RSS Forums RSS

Help with Measurement converter

Please support our C++ advertiser: Programming Forums
Thread Solved
Reply
Posts: 5
Reputation: XxAaronxX is an unknown quantity at this point 
Solved Threads: 0
XxAaronxX XxAaronxX is offline Offline
Newbie Poster

Help with Measurement converter

  #1  
Nov 25th, 2008
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

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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 2,362
Reputation: niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of 
Solved Threads: 256
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Nearly a Posting Maven

Re: Help with Measurement converter

  #2  
Nov 25th, 2008
2 things.
Change :
namespace std; to using namespace std; . Your code shouldn't compile without changing it.

then change:
  1. int Meters;
  2. int Yards;
to:
  1. double Meters;
  2. 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!
Reply With Quote  
Posts: 302
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 56
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: Help with Measurement converter

  #3  
Nov 25th, 2008
The mistake is that you are using integers (the set 0,1,2,3 and -1 etc)
to represent floating point number.
int a=2*1.2; gives sets a to 2.

write
  1. double Meters;
  2. double Yards;
instead of the two int declarations.
Reply With Quote  
Posts: 5
Reputation: XxAaronxX is an unknown quantity at this point 
Solved Threads: 0
XxAaronxX XxAaronxX is offline Offline
Newbie Poster

Re: Help with Measurement converter

  #4  
Nov 25th, 2008
Thanks for the help niek_e and StuXYZ it works perfectly now and i cant believe i forgot to put using before namespace.
Last edited by XxAaronxX : Nov 25th, 2008 at 5:51 am.
Reply With Quote  
Posts: 5
Reputation: XxAaronxX is an unknown quantity at this point 
Solved Threads: 0
XxAaronxX XxAaronxX is offline Offline
Newbie Poster

Re: Help with Measurement converter

  #5  
Nov 26th, 2008
Hey I Use Visual 2008 C++ Express and i don't know how to link this code to a GUI so that when i type the number of meters into a text box and press a button it will return the answer in a second text box. If you know of a tutorial on GUI's i could use it would be great.

Thanks
Reply With Quote  
Posts: 5
Reputation: XxAaronxX is an unknown quantity at this point 
Solved Threads: 0
XxAaronxX XxAaronxX is offline Offline
Newbie Poster

Re: Help with Measurement converter

  #6  
Nov 26th, 2008
Hey I have decided that a GUI is to Advanced for me to try at the moment and am going to keep reading my book.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 344 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:30 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC