Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c++ program that prompts the user to take one of the following options:

ID: 3628087 • Letter: W

Question

Write a c++ program that prompts the user to take one of the following options: 1. convert a character to a decimal, octal, and hex value, 2. convert a distance or 3. Exit the program. The program needs to present options until user wants to exit. If a character conversion is selected, you should ask the user to enter a character and then display the decimal, octal, and hex value...Ex, if the user enters M, you would write: Character M is 77(decimal) 115(octal) and 4d (hex). If the user selects distance conversion, you must ask which conversion to perform: Inches to meters or Miles to kilometers. If user wants to exit the program present a goodbye message and exit program. You must use at least on switch statement and one if-else statement. You may use either a do while or while loop. Write mete and kilometer values to three decimal places.

Explanation / Answer

please rate - thanks

#include <iostream>
#include <iomanip>
using namespace std;
int menu();
int menu2();
void charConvert();
void measureConvert();
int main()
{int choice;
choice=menu();
while(choice!=3)
    {if(choice==1)
         charConvert();
     else
         measureConvert();
     choice=menu();
     }
cout<<"goodbye ";
system("pause");  
return 0;
}
int menu()
{int choice;
do
{cout<<"Enter your choice ";
cout<<"1. convert a character to a decimal, octal, and hex value ";
cout<<"2. convert a distance ";
cout<<"3. Exit the program ";
cin>>choice;
switch(choice)
{case 1:
case 2:
case 3: return choice;
default: cout<<"invalid entry ";
}
}while(choice<1||choice>3);
}
int menu2()
{int choice;
do
{cout<<"Enter your choice ";
cout<<"1. Inches to meters ";
cout<<"2. Miles to kilometers ";
cin>>choice;
switch(choice)
{case 1:
case 2: return choice;
default: cout<<"invalid entry ";
}
}while(choice<1||choice>2);
}
void charConvert()
{char c;
cout<<"Enter a character: ";
cin>>c;
cout<<"character "<<c<<" is "<<(int)c<<"(decimal) "<<oct<<(int)c<<"(octal) ";
cout<<hex<<(int)c<<"(hex)"<<endl;
}
void measureConvert()
{int choice;
double n;
choice=menu2();
cout<<"enter value to convert: ";
cin>>n;
if(choice==1)
     cout<<n<<" inches is "<<setprecision(3)<<fixed<<n*.0254<<" meters"<<endl;
else
     cout<<n<<" miles is "<<setprecision(3)<<fixed<<n*1.609344<<" kilometers"<<endl;
     }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote