Circuit Negma

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

converter — Bug with the Check function

Posted by Circuit Negma on February 24, 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>

using namespace std;

float check()
{
 int n;
 bool flag = true;
 bool flagy;
 
 cin.clear();
 flag = cin >> n;
 
 while (!flag)
 {
       cout << endl;
       cout << “this is not a number” << endl;
       cout << ” you entered :  ” << n << endl;
       cout << “please enter a number again: “;
       cin.clear();
       cin.ignore();
}
       cout << “this is n:  ” << n << endl << endl;
      
/* while(flag)
 {
         cin.clear();
         flagy = cin >> i;
        
         if (flagy == 1 )
         {
             cout << “this is a number” << endl;
             cout << flagy << endl;
             flag = false;
             //return (float) i;   
         }
         else
         {
             cout << “this is not a number” << endl;
             cout << flagy << endl;
         }
 }*/
 
  return (float) n;

}

void cmConv (float n)
{
     float 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 (float 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 (float 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;
}

int main()
{
    cout.flush();
   
    int i;
    float icm, iin, ift;
    string flag;
   
    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:   
    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 Sat. Link System.       |” << endl;
    cout << endl;
    cout << ” Please, Chose from the Menu: “;
    cin  >> i;
    cout << endl;
   
    if ( i == 1 )
    {
         cout << “You chosed to convert from ‘cm’ to … ” << endl;
         cout << “Please, Enter the amount in ‘cm’:  “;
         icm = check();
         cout << icm;
         cmConv(icm);
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 2)
    {
         cout << “You chosed to convert from ‘inch’ to … ” << endl;
         cout << “Please, Enter the amount in ‘inch’:  “;
         cin >> iin;
         inchConv (iin);
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 3)
    {
         cout << “You chosed to convert from ‘ft’ to … ” << endl;
         cout << “Please, Enter the amount in ‘ft’:  “;
         cin >> ift;
         ftConv (ift);
         cout << endl << endl;
         goto main_face;
    }
    else if (i == 4)
    {
             cout << “Exit Sat. Link System.”;
            
    }
    else
    {
        cout << “exit”;
    }
   
    //cin >> i;
    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: