2 Replies - 795 Views - Last Post: 15 September 2008 - 04:04 AM Rate Topic: -----

#1 alienglow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-September 08

HELP on converting units

Post icon  Posted 14 September 2008 - 11:54 PM

 
	double  height;
	
	double cm_per_inch=2.54;
	int feet=0;
	int inch=0;
	 
	cout << "height (feet'inch):";
	cin >> feet >> inch;
	height = (feet * 12 + inch) * cm_per_inch / 100;
	
	cout << "my height is"
		 << height
		 << "meter"
		 << endl;



I juz started learning C++ programming. I am trying to convert feet and inches into meter. But this does not work. And i am not sure how to make it into a way which i can input the values like 5'4 and let the program understand that it means 5 feet and 4 inches.

So what's wrong with the codes and how can i make it understand 5'4 (or 3'5, 6'10, etc...) ??

Thank you

This post has been edited by alienglow: 15 September 2008 - 12:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: HELP on converting units

#2 sensui   User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 146
  • Joined: 24-August 08

Re: HELP on converting units

Posted 15 September 2008 - 01:26 AM

You can use a temporary variable for storing the character ' like char ch.
Example:
#include <iostream>
using namespace std;

int main() {
  double  height;
  const double cm_per_inch = 2.54;
  int feet, inch;

  char ch;  //for reading the character '
  
  cout << "height ( feet'inch ): ";
  cin >> feet >> ch >> inch;  //reading '
  height = ( feet * 12 + inch ) * cm_per_inch / 100;
  cout << "my height is "
       << height
       << " meters "
       << endl;

  cin.get();
  return EXIT_SUCCESS;
}



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 alienglow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-September 08

Re: HELP on converting units

Posted 15 September 2008 - 04:04 AM

View Postsensui, on 15 Sep, 2008 - 01:26 AM, said:

You can use a temporary variable for storing the character ' like char ch.
Example:
#include <iostream>
using namespace std;

int main() {
  double  height;
  const double cm_per_inch = 2.54;
  int feet, inch;

  char ch;  //for reading the character '
  
  cout << "height ( feet'inch ): ";
  cin >> feet >> ch >> inch;  //reading '
  height = ( feet * 12 + inch ) * cm_per_inch / 100;
  cout << "my height is "
       << height
       << " meters "
       << endl;

  cin.get();
  return EXIT_SUCCESS;
}



Hope this helps.



This really helps
thx a lot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1