- #1
Desi23
- 7
- 0
I'm making a program for one of my programming classes and just needed some help!
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int number;
float feet;
float metres;
float conv1;
float conv2;
cout << "Do you wish to convert 1. feet to metres or 2. metres to feet?" << "\n";
cout << "Enter your choice here:";
cin >>number;
cout <<"\n";
if (number==1)
{ cout << "Enter the distance in feet:";
cin >> feet;
cout <<"\n";
conv1= feet * 0.3048;
cout << setprecision(4) << fixed << feet << setw(8) << "feet is" << setw(7) << conv1 << setw(9) << "metre(s)" << "\n";
return 0;
}
else (number==2);
{ cout << "Enter the distance in metres:";
cin >> metres;
cout <<"\n";
conv2= metres * 3.2808;
cout << setprecision(4) << fixed << metres << setw(12) << "metre(s) is" << setw(7) << conv2 << setw(5) << "feet" << "\n";
}
return 0;
I have that so far, and I can't figure out how to write the code if somebody enters a number other then 1 or 2 it will output an "invalid" message. Can somebody help me out here this is driving me crazy lol.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int number;
float feet;
float metres;
float conv1;
float conv2;
cout << "Do you wish to convert 1. feet to metres or 2. metres to feet?" << "\n";
cout << "Enter your choice here:";
cin >>number;
cout <<"\n";
if (number==1)
{ cout << "Enter the distance in feet:";
cin >> feet;
cout <<"\n";
conv1= feet * 0.3048;
cout << setprecision(4) << fixed << feet << setw(8) << "feet is" << setw(7) << conv1 << setw(9) << "metre(s)" << "\n";
return 0;
}
else (number==2);
{ cout << "Enter the distance in metres:";
cin >> metres;
cout <<"\n";
conv2= metres * 3.2808;
cout << setprecision(4) << fixed << metres << setw(12) << "metre(s) is" << setw(7) << conv2 << setw(5) << "feet" << "\n";
}
return 0;
I have that so far, and I can't figure out how to write the code if somebody enters a number other then 1 or 2 it will output an "invalid" message. Can somebody help me out here this is driving me crazy lol.