could anyone help? I\'m lost:( his exercise, you will create a program that disp
ID: 3804436 • Letter: C
Question
could anyone help? I'm lost:(
Explanation / Answer
C++ code:
#include <bits/stdc++.h>
using namespace std;
float cmtoinch(float n)
{
return n*(0.393701);
}
float inchtocm(float n)
{
return (n/0.393701);
}
int main()
{
cout << "Enter 1 to convert From CM to Inch" << endl;
cout << "Enter 2 to convert From Inch to CM" << endl;
int c;
cin >> c;
if(c = 1)
{
cout << "Enter length in cm!" << endl;
float len;
cin >> len;
cout << len << " CM = " << cmtoinch(len) << " Inch!" << endl;
}
else if(c = 2)
{
cout << "Enter length in Inch!" << endl;
float len;
cin >> len;
cout << len << " Inch = " << inchtocm(len) << " CM!" << endl;
}
else
{
cout << "Invalid input!" << endl;
}
return 0;
}
Sample Output:
Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
1
Enter length in cm!
1
1 CM = 0.393701 Inch!
C:UsersAkashDesktopcheggc++ io>a
Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
2
Enter length in cm!
0.393702
0.393702 CM = 0.155001 Inch!
C:UsersAkashDesktopcheggc++ io>a
Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
3
Enter length in cm!
3
3 CM = 1.1811 Inch!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.