u

Friday 14 September 2012

C++ Program to Conversion program using Fucntions

C++ Program to Conversion program using Fucntions

#include <iostream.h>
#include <stdlib.h>

char choosestd;
float inch1;
float inch2;
float foot;
float yard;
float mile;
float millimeter;
float centimeter;
float meter1;
float meter2;
float kilometer;

int first;
float firstfunction();
float secondfunction();
float thirdfunction();
float fourthfunction();
float fifthfunction();
float sixthfunction();
float seventhfunction();
float eigthfunction();
float ninthfunction();
float tenthfunction();


int main()
{
      clrscr();
      cout << "*-------------------------------------------------------------*\n";
      cout << " \n\n\n";
      cout << "To (q)uit any time type enter \"q\"\n\n";
      cout << "To convert from Standard Measurments to Metric enter \"1\": \n";
      cout << "To convert from Metric to Standard Measurments enter \"2\": \n";
      cin >> first;

if (first == 1)
{
      int choosestd;
      cout << "What would you like to convert?\n";
      cout << "(1)Inches to Millimeters: \n";
      cout << "(2)Inches to Centimeters: \n";
      cout << "(3)Feet to Meters: \n";
      cout << "(4)Yards to Meters: \n";
      cout << "(5)Miles to Kilometers: \n";
      cin >> choosestd;

if (choosestd == 1)
     {
      cout << "\nEnter the number of inches you wish converted: \n";
      cin >> inch1;

      cout << "You entered " << inch1 ;
      cout<< " inches, which equals " << firstfunction() << " millimeters.\n\n";

      system("PAUSE");
      return main();
      }

else if     (choosestd == 2)
      {
      cout << "\nEnter the number of inches you wish converted: \n";
      cin >> inch2;

       cout << "You entered " << inch2 << " inches, which equals " << secondfunction() << " centimeters.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 3)
      {
      cout << "\nEnter the number of feet you wish converted: \n";
      cin >> foot;

      cout << "You entered " << foot << " feet, which equals " << thirdfunction() << " meters.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 4)
      {
      cout << "\nEnter the number of yards you wish converted: \n";
      cin >> yard;

      cout << "You entered " << yard << " yards, which equals " << fourthfunction() << " meters.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 5)
      {
      cout << "\nEnter the number of miles you wish converted: \n";
      cin >> mile;

      cout << "You entered " << mile << " miles, which equals " << fifthfunction() << " kilometers.\n\n";

      system("PAUSE");
      return main();
      }
else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5))
      {
      cout<<endl;
      cout << "\n\nThank you for using this program.\n\n";
      cout<<"endl";
      getch();

      return 0;
      }
}

else if (first == 2)
{
      int choosestd;
      cout << "What would you like to convert?\n";
      cout << "(1)Millimeters to Inches: \n";
      cout << "(2)Centimeters to Inches: \n";
      cout << "(3)Meters to Feet: \n";
      cout << "(4)Meters to Yards: \n";
      cout << "(5)Kilometers to Miles: \n";
      cin >> choosestd;

if (choosestd == 1)
     {
      cout << "\nEnter the number of millimeters you wish converted: \n";
      cin >> millimeter;

      cout << "You entered " << millimeter << " millimeters, which equals " << sixthfunction() << " inches.\n\n";

      system("PAUSE");
      return main();
      }

else if     (choosestd == 2)
      {
      cout << "\nEnter the number of centimeters you wish converted: \n";
      cin >> centimeter;

       cout << "You entered " << centimeter << " centimeters, which equals " << seventhfunction() << " inches.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 3)
      {
      cout << "\nEnter the number of meters you wish converted: \n";
      cin >> meter1;

      cout << "You entered " << meter1 << " meters, which equals " << eigthfunction() << " feet.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 4)
      {
      cout << "\nEnter the number of meters you wish converted: \n";
      cin >> meter2;

      cout << "You entered " << meter2 << " meters, which equals " << ninthfunction() << " yards.\n\n";

      system("PAUSE");
      return main();
      }
else if     (choosestd == 5)
      {
      cout << "\nEnter the number of kilometers you wish converted: \n";
      cin >> kilometer;

      cout << "You entered " << kilometer << " kilometers, which equals " << tenthfunction() << " miles.\n\n";

      system("PAUSE");
      return main();
      }
else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5))
      {
      int x;
      cout << "\n\nThank you for using this program.\n\n";
      cin >> x;

      return 0;
      }

}



else if ((first != 1) || (first != 2))
{
      int x;
      cout << "End Program.\n\n\nThis program was brought to you by\n             http://www.mcarterbrown.com\n\n\n";
      cout << "Thank you\n\n\n";
      cin >> x;

      return 0;
}

}
float firstfunction()
      {
      double x;
      x = (inch1 * 25.4);
      return x;
      }
float secondfunction()
      {
      double x;
      x = (inch2 * 2.54);
      return x;
      }
float thirdfunction()
      {
      float x;
      x = (foot * .3048);
      return x;
      }
float fourthfunction()
      {
      float x;
      x = (yard * .9144);
      return x;
      }
float fifthfunction()
      {
      float x;
      x = (mile * 1.609);
      return x;
      }
float sixthfunction()
      {
      float x;
      x = (millimeter / 25.4);
      return x;
      }
float seventhfunction()
      {
      float x;
      x = (centimeter / 2.54);
      return x;
      }
float eigthfunction()
      {
      float x;
      x = (meter1 / .3048);
      return x;
      }
float ninthfunction()
      {
      float x;
      x = (meter2 / .9144);
      return x;
      }
float tenthfunction()
      {
      float x;
      x = (kilometer / 1.609);
      return x;
      }

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More