How do I make this not case sensitive? If I put in Pyramid, it will run the pyramid function, but if I put in pyramid, it recognizes it as else and runs the cube function
//If volume, ask is cube or pyramid
else
{
string shapeVolume = "";
cout << "What is the shape (Pyramid or Cube)?\n";
cin >> shapeVolume;
//If pryamid, ask for 2 values
if (shapeVolume == "Pyramid")
{
double basePyramid = 0;
cout << "What is the base length?\n";
cin >> basePyramid;
double heightPyramid = 0;
cout << "What is the height?\n";
cin >> heightPyramid;
//Multiply 2 values, divide by 3
double pyramidProduct = (basePyramid * heightPyramid) / 3;
//Give result
cout << "The volume of the pyramid is " << pyramidProduct << ".\n";
return 0;
}
//If cube, ask for the value
else
{
double baseCube = 0;
cout << "What is the base length?\n";
cin >> baseCube;
//multiply base^3
double cubeProduct = baseCube * baseCube * baseCube;
//Give result
cout << "The volume of the cube is " << cubeProduct << ".\n";
return 0;
Also, I'm trying to make it so that if the user does not choose "area" or "volume" it will lopp around and ask again but I get an error on line 16 with the &&
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
#include <math.h>
usingnamespace std;
int main()
{
//Get area or volume
string areaVolume = "";
do
{
cout << "Are you trying to find the area or volume?\n";
cin >> areaVolume;
} while (areaVolume = "area" && areaVolume = "volume");
If you are trying to re-run the do-while loop when the user fails to enter "area"/"volume"?..
Then you have to use
!=
in place of a single
=
. A single "=" is used for assignment. For comparision, we use "==" , "!=" , "<" , ">" , "<=", ">=".
That error is coming because you are assigning instead of comparing. Use