Write a C program that prompts the user to enter the number
Write a C++ program that prompts the user to enter the number of inches as an integer number. The program should then prompt the user to enter the units to convert to as a string. The allowable strings that can be entered are: feet, yards, miles, meters, and kilometers. The entries for units can be in any case. For example, feet, Feet, FEET, and fEEt are all allowable entries. Use a C++ switch statement to convert, and display the converted value, which will be converted from inches to the units specified by the user.
Solution
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int main(){
int conv;
int inches;
string units;
cout<<\"enter the number of inches as an integer number\";
cin>>inches;
cout<<\"enter the units in which you want to convert\" ;
cin>>units;
cout<<units;
for(int i=0;units.length();i++)
{
char ch=units.at(i);
units.at(i)=toupper(ch);
}
switch(units){
case \"FEET\" :
conv=inches*0.0833333;
break;
case \"YARDS\" :
conv=inches*0.0277778;
break;
case \"MILES\" :
conv=inches*1.57828e-5;
break;
case \"KILOMETERS\" :
conv=inches*2.54e-5;
break;
case \"METERS\" :
conv=inches*0.0254;
break;
default :
cout << \"There is no such name in database!\" << endl;
}
getch();
return conv;
}
