so i was wondering if my program could be converted to a string version, if so gimme a start please. I also would like to find out how to set my speed variable if when entered it is less than zero for it to display an error statement, how would I do this in switch and or string. thanks so much.
// This program will calculate the speed of sound
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice; //to hold a menu choice
int speed; //to hold the speed
double charges; // to hold the monthly charges
//const for air
const double AIR = 1100.0,
WATER = 4900.0,
STEEL = 16400.0;
//constants for menu choice
const int air_choice = 1,
water_choice = 2,
steel_choice = 3,
quit_choice = 4;
//display menu and get a choice
cout << "\t\tSelect one of the folowing from the menu\n\n"
<< "1. air\n"
<< "2. water\n"
<< "3. steel\n"
<< "4. quit the program\n\n"
<< "Enter your choice:";
cin >> choice;
// set the numeric formating.
cout << fixed << showpoint << setprecision(4);
// respond to the users menu choice
switch (choice)
{
case air_choice:
cout << " Enter the speed of the sound in air please:";
cin >> speed;
charges = AIR / speed;
cout << "\t\tthe total speed of sound in Air is:" << charges <<"Htz"<< endl;
break;
case water_choice:
cout << " Enter the speed of the sound in water please:";
cin >> speed;
charges = WATER / speed;
cout << "\t\tthe total speed of sound in water is:" << charges <<"Htz"<< endl;
case steel_choice:
cout << " Enter the speed of the sound in steel please:";
cin >> speed;
charges = STEEL / speed;
cout << "\t\tthe total speed of sound in steel is:" << charges <<"Htz"<< endl;
break;
case quit_choice:
cout << " This program will self destruct now!:";
break;
default:
cout << " That is not a valid choice now i have to eat your soul!! Run the \n"
<< "program again and select one through four please!\n";
}
system("PAUSE");
return 0;
}