Hi can somebody please help me work out this c++ program. We are trying to figur
ID: 3689493 • Letter: H
Question
Hi can somebody please help me work out this c++ program. We are trying to figure out how to write a program where the conversion process code is originally developed (we have to do all 6 conversions listed below) We are trying to use case switch statements but are getting stuck in what way and how to use the proper formulas. This program should continue looping until the user says that they do not want to perform another conversion. Thank you so much! Please help me understand the process as well! (This is where I am stuck right now)
#include
#include
using namespace std;
int main()
{
int opselect;
double xnum, ynum;
cout << "Please enter a number: ";
cin >> xnum;
cout << "What type of conversion would you like to compute?: ";
cout << " 1 for decimal to binary";
cout << " 2 for decimal to hexadecimal";
cout << " 3 for binary to decimal";
cout << " 4 for binary to hexadecimal";
cout << " 5 for hexadecimal to binary";
cout << " 6 for hexadecimal to decimal";
cin >> opselect;
switch (opselect)
{
case 1:
cout << "The result of the conversion is: " << ynum;
break;
case 2:
cout << "The result of the conversion is: " <<
break;
case 3:
cout << "The result of the conversion is: " <<
break;
case 4:
cout << "The result of the conversion is: " <<
break;
case 5:
cout << "The result of the conversion is: " <<
break;
case 6:
cout << "The result of the conversion is: " <<
break;
}
cout << endl;
return 0;
}
Explanation / Answer
#include
#include
using namespace std;
int main()
{
int opselect;
double xnum, ynum;
do
{
cout << "Please enter a number: ";
cin >> xnum;
cout << "What type of conversion would you like to compute?: ";
cout << " 1 for decimal to binary";
cout << " 2 for decimal to hexadecimal";
cout << " 3 for binary to decimal";
cout << " 4 for binary to hexadecimal";
cout << " 5 for hexadecimal to binary";
cout << " 6 for hexadecimal to decimal";
cout<<" 0 for exit";
cin >> opselect;
switch (opselect)
{
case 1:
cout << "The result of the conversion is: " << ynum;
break;
case 2:
cout << "The result of the conversion is: " <<
break;
case 3:
cout << "The result of the conversion is: " <<
break;
case 4:
cout << "The result of the conversion is: " <<
break;
case 5:
cout << "The result of the conversion is: " <<
break;
case 6:
cout << "The result of the conversion is: " <<
break;
}while(opselect!=0);
}
cout << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.