Can someone check my Math.
Can someone check my Math.
Can someone check my Math.
Can someone check my Math.
Can someone check my Math.
Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math.
Can someone check my Math. Can someone check my Math.
Can someone check my Math.
Go Back  Xtreme Visual Basic Talk > > > Can someone check my Math.


Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2014, 10:22 AM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default Can someone check my Math.


I am using Visual basic 2013 express, This program takes an input in meters an outputs it in yards, feet, an inches. Thank you for the help.

Code:
#include "stdafx.h"
#include <iostream>
using namespace std;


int inputMeters, yards, feet;
double inches;

int main()
{
	cout << "Enter in a length in meters to be converted into yards, feets, and inches. " << endl;
	cin >> inputMeters;
	inches = inputMeters * 39.37;
	while (inches > 12)
	{
		if (inches > 12)
			inches = inches - 12;
			feet++;

			if (feet > 3)
				feet = feet - 3;
				yards++;
			
	}
		yards = yards / 3;
	cout << yards << " " << feet << " " << inches << endl;
	return 0;
}
__________________
"When all else fails, read the manual."
Reply With Quote
  #2  
Old 09-06-2014, 03:55 PM
Gruff's Avatar
GruffCan someone check my Math. Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

C# is not my language and math is not my expertise.
However if I were to do this sort of units converter I would use integer division
to get the coarsest value first then modulus to get the remainder. Repeat for each unit.

Not sure why you are using a loop.

'VB Code
Code:
Private Function DisplayYardsFeetInches(Meters As Double) As String Dim Inches As Double = Meters * 39.3701 Dim Yards As Integer = Inches \ 36 Inches = Inches Mod 36 Dim Feet As Integer = Inches \ 12 Inches = Inches Mod 12 Return Yards.ToString & " Yards " & Feet.ToString & " Feet " & Inches.ToString("0.000") & " Inches" End Function
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 09-08-2014, 10:19 AM
EMetalmulishaH's Avatar
EMetalmulishaH EMetalmulishaH is offline
Freshman
 
Join Date: Mar 2012
Location: NO WHERE
Posts: 39
Default

Thank you, I did not think to use integer division, I was trying to over complicate the problem.
__________________
"When all else fails, read the manual."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Can someone check my Math.
Can someone check my Math.
Can someone check my Math. Can someone check my Math.
Can someone check my Math.
Can someone check my Math.
Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math. Can someone check my Math.
Can someone check my Math.
Can someone check my Math.
 
Can someone check my Math.
Can someone check my Math.
 
-->