C++ conversion program

How can I write a program that convert a given number of millimeters into the equivalent length in meters and meters into the equivalent length in millimeters?Also draw flowchart,algorithm,output.

Questions by salom

Showing Answers 1 - 2 of 2 Answers

Manish Kumar

  • Jan 8th, 2015
 

Code
  1. #include <iostream>

  2. using namespace std;

  3.  

  4.  

  5. int main ()

  6. {

  7.     int iOption;

  8.     int iValue;

  9.  cout<<"1 for meter to mm and 2 for mm to meter. so enter your option."<<endl;

  10.  cin>>iOption;

  11.  switch(iOption)

  12.  {

  13.      case 1:

  14.      cout<<"It is meter to mm. Please enter the value"<<endl;

  15.      cin>>iValue;

  16.      cout<<"Your meter to mm is: "<<iValue*1000;

  17.      break;

  18.      

  19.      case 2:

  20.      cout<<"It is mm to meter. Please enter the value"<<endl;

  21.      cin>>iValue;

  22.      cout<<"Your mm to meter is: "<<iValue/1000;

  23.      

  24.  }

  25.   return 0;

  26. }


  Was this answer useful?  Yes

John

  • Feb 15th, 2015
 



Code
  1. void Convert(const char* str)

  2. {

  3.         size_t len = strlen(str);

  4.  

  5.         //

  6.         if(str[len-1] != m || len < 2 || !isdigit(*str))

  7.         {

  8.                 std::cout << "Invalid argument" << std::endl;

  9.                 return;

  10.         }

  11.  

  12.         //

  13.         if(str[len-2] == m)

  14.         {

  15.                 // mm

  16.                 std::cout << str << " = " << atoi(str)/1000 << "m";

  17.         }

  18.         else

  19.         {

  20.                 // m

  21.                 std::cout << str << " = " << atoi(str)*1000 << "mm";

  22.         }

  23. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions