Okay I made a prog its for temperature conversion its still not developed yet and Im having problems
heres the code
the problem is when you go to Celsius Converter and there input alphabets then the programs start looping infinitelyCode:/* Software Name = Temperature Converter Calculator...
Made by Manzoor Ahmed.*/
// Program that helps converting Temperature degrees.
// Formulas obtained from wikipedia.org.
#include <cstdlib>
#include <cctype>
#include <iostream>
using namespace std;
int CelFunc() ;
void CnvrtTemp()
{
char Cnvrt_Temp_Option ;
cout << "\n==================== Convert Temperature =======================" << endl ;
do
{
cout << "\n\n[C] Celsius Converter" << endl ;
cout << "[F] Fahrenheit Converter" << endl ;
cout << "[K] Kelvin Converter" << endl ;
cout << "[R] Rankine Converter" << endl ;
cout << "[M] Back to Main Menu." << endl ;
cout << "\n(Characters enclosed by the square brackets are the options.)" << endl ;
cout << "\nEnter your option: " ;
cin >> Cnvrt_Temp_Option ;
if ( Cnvrt_Temp_Option == 67 || Cnvrt_Temp_Option == 99 ) // 67 == C 99 == c
{
CelFunc();
}
// 70 = F and 102 = f
if ( Cnvrt_Temp_Option == 70 || Cnvrt_Temp_Option == 102 )
{
cout << "FahrFunc()" << endl ;
}
if ( Cnvrt_Temp_Option == 75 || Cnvrt_Temp_Option == 107 )
{
cout << "KelFunc()" << endl;
}
if ( Cnvrt_Temp_Option == 82 || Cnvrt_Temp_Option == 114 )
{
cout << "RankFunc()" << endl ;
}
} while (!( Cnvrt_Temp_Option == 77 || Cnvrt_Temp_Option == 109 )); // 77 == M and 109 == m
}
int main()
{
char Main_Menu_Option;
// program name output
cout << "################################################################################";
cout << "# #";
cout << "# #";
cout << "# #";
cout << "# Temperature Converter Calculator #";
cout << "# #";
cout << "# #";
cout << "# #";
cout << "# #";
cout << "################################################################################\n\n";
do
{ // Main Menu
cout << "\n================================ Main Menu =====================================\n\n\n";
// Menu
cout << "[C] Convert Temperature" << endl ;
cout << "[H] Help" << endl ;
cout << "[E] Exit" << endl ;
cout << "\n(Characters enclosed by the square brackets are the options.)\n" << endl ;
cout << "\nEnter your option : ";
cin >> Main_Menu_Option ;
// Following I have used ASCII numbers to check the input from user
// whether the input is correct or not
// 67 = C, 99 = c, 72 = H, 104 = h, 69 = E, 101 = e .
if (!( Main_Menu_Option == 67 || Main_Menu_Option == 99 || Main_Menu_Option == 72 || Main_Menu_Option == 104 || Main_Menu_Option == 69 || Main_Menu_Option == 101 ))
{
cout << "\nWrong option entered\n";
}
// 67 == C, 99 == c, 72 == H, 104 == h, 69 == E, 101 == e .
if ( Main_Menu_Option == 67 || Main_Menu_Option == 99) // 67 == C , 99 == c.
{
CnvrtTemp();
}
if ( Main_Menu_Option == 69 || Main_Menu_Option == 104 )
{
cout << "Help section is under construction.\n";
}
} while (!( Main_Menu_Option == 69 || Main_Menu_Option == 101 ));
system ("pause");
return 0;
}
int CelFunc()
{ char again;
cout << "\n=============================== Celsius Converter ==============================\n\n" ;
do {
cout << "Enter °C (Celsius) degree to convert :";
long double cTemp2Conv;
cin >> cTemp2Conv;
if (isdigit(cTemp2Conv)) {
long double cFahrenheit = (cTemp2Conv * 1.8) + 32;
long double cKelvin = cTemp2Conv + 273.15;
long double cRankine = (cTemp2Conv + 273.15) * 1.8;
cout << "\nAnswer: " << cTemp2Conv << " Celsius in Fahnrenheit scale = " << cFahrenheit;
cout << "\nAnswer: " << cTemp2Conv << " Celsius in Kelvin scale = " << cKelvin;
cout << "\nAnswer: " << cTemp2Conv << " Celsius in Rankine scale = " << cRankine;
cout << "\n\n";
}
else {
cout << "\nINVALID INPUT !";
cout << "\nPlease enter numerical values.\n";
}
cout << "\nDo you want to convert temperature again ?";
cout << "\nEnter Y for yes, N for no.";
cout << "\nEntering wrong option other than Y/N will result in getting back to \nConvert Temprature menu.";
cout << "\n[y]/[n]:";
cin >> again;
} while (again == 'y'|| again == 'Y');
}
I tried cin.good() and isdigit() for checking the input but both gave me same results
any help is really appreciated
thanks