Hi, Can i get some help on the following code. I wrote it but it keeps giving me errors saying cin is ambiguous, and the else error no matching if.
using visual studio 32winproject here is the code
*Description: Create a program which prompts the user for an integer number representing the user's choice of beam type, 1 for an I-beam,
*2 for a rectangular beam, 3 for a cylindrical beam. After the user has chosen the type of beam, the program should prompt the user for
*for the necessacry measurements data (based on the type of beam), and then compute and display the beam's moment of inertia.*/
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double I;
double B, H, b, h, r;
const double PI = 3.1416;
char choice;
cout << "Enter the type of beam and make a choice from the beams: ";
cin >> choice;
if (choice == '1');
{
cout << "Enter the width of the part of the I beam in inches: ";
cin >> b;
cout << "Enter the height of the part of the I beam in inches: ";
cin >> h;
cout << "Enter the Breath of the part of the I beam in inches: ";
cin >> B;
cout << "Enter the height of the part of the I beam in inches: ";
cin >> H;
I = ((B*H*H*H) - (b*h*h*h)) / 12;
cout << "The moment of Inertia I in inches is: " << I << endl;
}
else if (choice == '2');
{
cout << "Enter the breath of the Rectangular Beam in inches: ";
cin >> b;
cout << "Enter the height of the Rectangular Beam in inches: ";
cin >> h;
I = (b *(h*h*h)) / 12;
cout << "The moment of Inertia I in inches is: " << I << endl;
}
else if (choice == '3');
{
cout << "Enter the Radius of the Cylindrical beam: ";
cin >> r;
I = (PI * (r*r*r*r)) / 4;
cout << "The moment of Inertia I is: " << I << endl;
#include <iostream>
int main()
{
double I;
double B, H, b, h, r;
constdouble PI = 3.1416;
char choice;
std::cout << "1 I Beam ";
std::cout << "2 Rectangular Beam ";
std::cout << "3 Cylindrical Beam ";
std::cout << "Enter the type of beam and make a choice from the beams: ";
std::cin >> choice;
if (choice == '1')
{
std::cout << "Enter the width of the part of the I beam in inches: ";
std::cin >> b;
std::cout << "Enter the height of the part of the I beam in inches: ";
std::cin >> h;
std::cout << "Enter the Breath of the part of the I beam in inches: ";
std::cin >> B;
std::cout << "Enter the height of the part of the I beam in inches: ";
std::cin >> H;
I = ((B * H * H * H) - (b * h * h * h)) / 12.0;
std::cout << "The moment of Inertia I in inches is: " << I << '\n';
}
elseif (choice == '2')
{
std::cout << "Enter the breath of the Rectangular Beam in inches: ";
std::cin >> b;
std::cout << "Enter the height of the Rectangular Beam in inches: ";
std::cin >> h;
I = (b *(h * h * h)) / 12.0;
std::cout << "The moment of Inertia I in inches is: " << I << '\n';
}
elseif (choice == '3')
{
std::cout << "Enter the Radius of the Cylindrical beam: ";
std::cin >> r;
I = (PI * (r * r * r * r)) / 4.0;
std::cout << "The moment of Inertia I is: " << I << '\n';
}
}
This compiles successfully with MS Visual C++ 2017, I can't say if the equations are calculating the correct results. Not my area of expertise. :)
When doing math operations on floating point variables I recommend not using integer constants, it could skew the results with an integer math operation. For example, use 4.0 instead of 4.