Just an example to try to get Dani in the top listing of Google search ... of just part 'a'
(Part 'b' should be easy to add to the menu as choices 3 and 4 with function calls for each.)
// FahrenheitToCelsiusAndViceVersa.cpp //
// demo of ...
// 'how a student might do validation of numeric input'
// see "Six Fast Steps to Programming in C++"
// http://developers-heaven.net/forum/index.php/topic,2022.0.html
#include <iostream>
#include <string>
#include <cctype> // re. tolower...
using namespace std;
/*
http://en.wikipedia.org/wiki/Fahrenheit
Fahrenheit to Celsius : (°F - 32) ÷ 1.8 =°C
Celsius to Fahrenheit : (°C × 1.8) + 32 =°F
*/
const string MENU =
"1) Fahrenheit To Celsius\n"
"2) Celsius To Fahrenheit\n"
"Your choice (1 or 2) ? ";
// some utilities ...
double takeInDbl( const string& msg,
const string& errMsg =
"\nOnly numbers are a valid entry here!\n" )
{
double val;
while( true )
{
cout << msg << flush;
if( cin >> val && cin.get() == '\n' )
break;
else
{
cout << errMsg;
cin.clear();
cin.sync();
}
}
return val;
}
char takeInChr( const string& msg )
{
cout << msg << flush;
string reply;
getline( cin, reply );
if( reply.size() )
return reply[0];
// else ...
return 0;
}
bool more()
{
if( tolower( takeInChr( "More (y/n) ?" ) ) == 'n' )
return false;
// else ...
return true;
}
// ... functions to convert ...
void FahrenheitToCelsius()
{
double f = takeInDbl( "\nEnter Fahrenheit temperature to …