Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Unit Converter – Beta ver 2.0

Posted by Circuit Negma on March 9, 2006


// ************************************************************************
// * Created By: Circuit Negma                                            *
// * Date      : Jan 1 , 2006                                             *
// * File Name : converter                                                *
// * Description :                                                        *
// * THIS IS a general metric converter                                   *
// ************************************************************************

// SEC. 1: PRE-PROCESSOR DIRECTIVES
// Library - is a collection of functions and symbols that are needed to run
//           C++ program.
// Library - has a name and is referred to by a header file.

#include <iostream>   // Input/Output functions are contained in the header
                        // file iostream.h
                        // The header file contain the needed instructions and
                        // descriptions of the functions needed to perform input
                        // output operations.
#include <cstdlib>
#include <stdlib.h>

using namespace std;

// ****************************************************************
// *** User Defined Functions ***
int checkmenu()
{
	 char str[256];
	 int n;
	 
label_check:
			 cin >> str;
			 n = atoi (str);
			 
			 if (n == 0)
			 {
			 	cout << "This is not a number" << endl;
			 	cout << "Please, Enter a number again: ";
			 	goto label_check;
			 }
       	   
			  return n;
}


float check()
{
	 char str[256];
	 double n;
	 
label_check:
			 cin >> str;
			 n = atof (str);
			 cout << "You have Entered: "<< n << endl;
			 
			 if (n == 0.0)
			 {
			 	cout << "This is not a number" << endl;
			 	cout << "Please, Enter a number again: ";
			 	goto label_check;
			 }
		       	   
			  return n;
}


void cmConv (double n)
{
     double iin, ift;
     
     cout << endl << endl;
     cout << " cmConv has been chosen" << endl;
     iin = n * 0.394;
     ift = n * 0.0328;
     cout << iin << " in" << endl;
     cout << ift << " ft" << endl;
}

void inchConv (double n)
{
      float incm, inft;
     
     cout << endl << endl;
     cout << " inchConv has been chosen" << endl;
     incm = n / 0.394;
     inft = (n * 0.0328) / 0.394;
     cout << incm << " cm" << endl;
     cout << inft << " ft" << endl;

}

void ftConv (double n)
{
     float ftcm, ftin;
     
     cout << endl << endl;
     cout << " ftConv has been chosen" << endl;
     ftcm = n / 0.0328;
     ftin = (n * 0.394) / 0.0328;
     cout << ftcm << " cm" << endl;
     cout << ftin << " in" << endl;
} 
//***************************************************************

//***************************************************************
//*** Build in Function main() ***
int main()
{
    cout.flush();
    int i;
    
    // *** Menu ***  
    cout << " _____________________________" << endl << endl;
    cout << " - Created By: Circuit Negma -" << endl;
    cout << " - File Name : Converter.cpp -" << endl;
    cout << " - Date      : Jan 17, 2006  -" << endl;
    cout << " _____________________________" << endl;
    cout << endl << endl;
main_face:                                                   // Label
    cout << " _________________________________"  << endl;
    cout << "|                                 |" << endl;
    cout << "| Welcome to C++                  |" << endl;
    cout << "|                                 |" << endl;
    cout << "| Metric Calculator Menu          |" << endl;
    cout << "|___________________________      |" << endl;
    cout << "|                                 |" << endl;
    cout << "| 1. Convert from 'cm' to ...     |" << endl;
    cout << "| 2. Convert from 'inch' to ...   |" << endl;
    cout << "| 3. Convert from 'ft' to ...     |" << endl;
    cout << "| 4. Exit ...                     |" << endl;
    cout << endl;
    cout << " Please, Choose from the Menu: ";
    i = checkmenu();
    cout << endl;
    
    if ( i == 1 )
    {
         cout << "You chose to convert from 'cm' to ... " << endl;
         cout << "Please, Enter the amount in 'cm':  ";
         cmConv(check());
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 2)
    {
         cout << "You chose to convert from 'inch' to ... " << endl;
         cout << "Please, Enter the amount in 'inch':  ";
         inchConv (check());
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 3)
    {
         cout << "You chose to convert from 'ft' to ... " << endl;
         cout << "Please, Enter the amount in 'ft':  ";
         ftConv (check());
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 4)
    {
             cout << "Exiting ...";
             
    }
    else
    {
        cout << "Please, Choose from the Menu" << endl;
        goto main_face;
    }
    
   
    return 0;
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: