- Joined
- Jan 17, 2004
ok using visual basic 2010 .. everything seems to look right to a noob like me but what id like to happen is to keep the program running ..until the exit command is used.
EDIT:
1. When entering correct numbers and options it works fine.
2. when entering an invalid character it jumps to error and would you like to continue. but even if you press Y it ends.
3. also after choosing option and entering a number to be converted. If i enter a 'J' instead of a number it will infinite loop ..
4. What am i doing wrong?
5. Anything else to help me get pointed in the right direction.
oh and im trying "do while" loops because thats the section we are in and he wants us to be able to be versatile with all loops doing different things ..
here is the copy of the cpp file .. simple text
///////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <conio.h>
#include <cmath>
#include <iomanip>
using namespace std;
int main ()
{
double celcius, fahrenheit;
string exit;
char choice;
cout << "This program is for converting Fahrenheit to Celsius or Celsius to Fahrenheit " << endl << endl;
do
{
cout << " \nPress 1 to convert Fahrenheit to Celsius " << endl << endl;
cout << "\nPress 2 to convert Celcius to Fahrenheit " << endl << endl;
cin >> choice;
if (choice == '1')
{
cout << "\nThis will convert Fahrenheit to Celcius " << endl << endl;
cout << "\nPlease enter a number to be converted" << endl << endl;
cin >> fahrenheit;
celcius = (fahrenheit - 32) * 5/9;
cout << "\nThe number you entered was " << fahrenheit << "\nThat number converted to Celcius is " << celcius << endl << endl;
}
else if (choice == '2')
{
cout << "\nThis will convert Celcius to Fahrenheit " << endl << endl;
cout << "\nPlease enter a number to be converted" << endl << endl;
cin >> celcius;
fahrenheit = celcius * 9/5 + 32;
cout << "\nThe number you entered was " << celcius << "\nThat number converted to Fahrenheit is " << fahrenheit << endl << endl;
}
else
{
cout << "\nYou entered an invalid number ......" ;
cout << "\n";
}
cout << "\nWould you like to continue ? Please press Y to continue or any other key to exit.... " << endl << endl;
cin >> exit;
}
while ((exit == "y") || (exit == "Y"));
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
EDIT:
1. When entering correct numbers and options it works fine.
2. when entering an invalid character it jumps to error and would you like to continue. but even if you press Y it ends.
3. also after choosing option and entering a number to be converted. If i enter a 'J' instead of a number it will infinite loop ..
4. What am i doing wrong?
5. Anything else to help me get pointed in the right direction.
oh and im trying "do while" loops because thats the section we are in and he wants us to be able to be versatile with all loops doing different things ..
here is the copy of the cpp file .. simple text
///////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <conio.h>
#include <cmath>
#include <iomanip>
using namespace std;
int main ()
{
double celcius, fahrenheit;
string exit;
char choice;
cout << "This program is for converting Fahrenheit to Celsius or Celsius to Fahrenheit " << endl << endl;
do
{
cout << " \nPress 1 to convert Fahrenheit to Celsius " << endl << endl;
cout << "\nPress 2 to convert Celcius to Fahrenheit " << endl << endl;
cin >> choice;
if (choice == '1')
{
cout << "\nThis will convert Fahrenheit to Celcius " << endl << endl;
cout << "\nPlease enter a number to be converted" << endl << endl;
cin >> fahrenheit;
celcius = (fahrenheit - 32) * 5/9;
cout << "\nThe number you entered was " << fahrenheit << "\nThat number converted to Celcius is " << celcius << endl << endl;
}
else if (choice == '2')
{
cout << "\nThis will convert Celcius to Fahrenheit " << endl << endl;
cout << "\nPlease enter a number to be converted" << endl << endl;
cin >> celcius;
fahrenheit = celcius * 9/5 + 32;
cout << "\nThe number you entered was " << celcius << "\nThat number converted to Fahrenheit is " << fahrenheit << endl << endl;
}
else
{
cout << "\nYou entered an invalid number ......" ;
cout << "\n";
}
cout << "\nWould you like to continue ? Please press Y to continue or any other key to exit.... " << endl << endl;
cin >> exit;
}
while ((exit == "y") || (exit == "Y"));
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
Last edited: