First I want to thank all the support for the community, you are all amazing. My issue is that when I run this program, it does not accept the "area" INT, is starts at the top of the loop and moves all the way through, even if I choose 2 to change the While, it continues one if statement after another, I have read, and checked everything I can, I would love some hints on why it is ignoring the input and just running through. Thank You again.
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
usingnamespace std;
int main()
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
//variable declaration
float area;//type of area to solve for
float side;//for the square
float radius;//for the circle
float radiussquared;//squared value of the radius
float width;//for the rectangle
float length;//for the rectangle
float base;//for the triangle
float height;//for the triangle
float trianglearea;//area of Triangle
float squarearea;//area of square
float circlearea;//area of circle
float rectanglearea;//area of rectangle
int decider;//for deciding whether to run another loop
//getting variable for while loop
decider = 1;
while (decider < 2) {
cout << "Please enter number for type of area to solve for (1=square, 2=circle, 3=rectangle, 4=triangle) ";
cin >> area;
if (area != 1);
cout << "Please input the size of one of the sides of the square ";
cin >> side;
squarearea = side * side;
cout << "the area of the square is " << squarearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes) ";
cin >> decider;
if (area != 2);
cout << "Please input the radius of the circle ";
cin >> radius;
radiussquared = radius * radius;
circlearea = radiussquared * M_PI;
cout << "The area of the Circle is " << circlearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
if (area != 3);
cout << "Please input the width of the rectangle ";
cin >> width;
cout << "Please input the length of the rectangle ";
cin >> length;
rectanglearea = width * length;
cout << "The area of the Rectangle is " << rectanglearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
if (area != 4);
cout << "Please input the height of the triangle ";
cin >> height;
cout << "Please input the base of the triangle ";
cin >> base;
trianglearea = (height * base) / 2;
cout << "The area of the Triangle is " << trianglearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
}
return 0;
}
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#define M_PI 3.14159
usingnamespace std;
int main()
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
//variable declaration
float area;//type of area to solve for
float side;//for the square
float radius;//for the circle
float radiussquared;//squared value of the radius
float width;//for the rectangle
float length;//for the rectangle
float base;//for the triangle
float height;//for the triangle
float trianglearea;//area of Triangle
float squarearea;//area of square
float circlearea;//area of circle
float rectanglearea;//area of rectangle
int decider;//for deciding whether to run another loop
//getting variable for while loop
decider = 1;
while (decider < 2)
{ //While Start
cout << "Please enter number for type of area to solve for (1=square, 2=circle, 3=rectangle, 4=triangle) ";
cin >> area;
if (area == 1)
{
cout << "Please input the size of one of the sides of the square ";
cin >> side;
squarearea = side * side;
cout << "the area of the square is " << squarearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes) ";
cin >> decider;
}
if (area == 2)
{
cout << "Please input the radius of the circle ";
cin >> radius;
radiussquared = radius * radius;
circlearea = radiussquared * M_PI;
cout << "The area of the Circle is " << circlearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
}
if (area == 3)
{
cout << "Please input the width of the rectangle ";
cin >> width;
cout << "Please input the length of the rectangle ";
cin >> length;
rectanglearea = width * length;
cout << "The area of the Rectangle is " << rectanglearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
}
if (area == 4)
{
cout << "Please input the height of the triangle ";
cin >> height;
cout << "Please input the base of the triangle ";
cin >> base;
trianglearea = (height * base) / 2;
cout << "The area of the Triangle is " << trianglearea << "\n";
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
}
} //End While
return 0;
}
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#define M_PI 3.14159
usingnamespace std;
int main()
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
//variable declaration
float area;//type of area to solve for
float side;//for the square
float radius;//for the circle
float radiussquared;//squared value of the radius
float width;//for the rectangle
float length;//for the rectangle
float base;//for the triangle
float height;//for the triangle
float trianglearea;//area of Triangle
float squarearea;//area of square
float circlearea;//area of circle
float rectanglearea;//area of rectangle
int decider;//for deciding whether to run another loop
//getting variable for while loop
decider = 1;
while (decider < 2)
{ //While Start
cout << "Please enter number for type of area to solve for (1=square, 2=circle, 3=rectangle, 4=triangle) ";
cin >> area;
if (area == 1)
{
cout << "Please input the size of one of the sides of the square ";
cin >> side;
squarearea = side * side;
cout << "the area of the square is " << squarearea << "\n";
}
if (area == 2)
{
cout << "Please input the radius of the circle ";
cin >> radius;
radiussquared = radius * radius;
circlearea = radiussquared * M_PI;
cout << "The area of the Circle is " << circlearea << "\n";
}
if (area == 3)
{
cout << "Please input the width of the rectangle ";
cin >> width;
cout << "Please input the length of the rectangle ";
cin >> length;
rectanglearea = width * length;
cout << "The area of the Rectangle is " << rectanglearea << "\n";
}
if (area == 4)
{
cout << "Please input the height of the triangle ";
cin >> height;
cout << "Please input the base of the triangle ";
cin >> base;
trianglearea = (height * base) / 2;
cout << "The area of the Triangle is " << trianglearea << "\n";
}
cout << "Do you wish to figure for another area? (1 for Yes, 2 for No) ";
cin >> decider;
} //End While
return 0;
}
switch (area) {
case 1:
cout << "Please input the size of one of the sides of the square ";
cin >> side;
squarearea = side * side;
cout << "the area of the square is " << squarearea << "\n";
break;
case 2:
cout << "Please input the radius of the circle ";
cin >> radius;
radiussquared = radius * radius;
circlearea = radiussquared * M_PI;
cout << "The area of the Circle is " << circlearea << "\n";
break;
case 3:
cout << "Please input the width of the rectangle ";
cin >> width;
cout << "Please input the length of the rectangle ";
cin >> length;
rectanglearea = width * length;
cout << "The area of the Rectangle is " << rectanglearea << "\n";
break;
case 4:
cout << "Please input the height of the triangle ";
cin >> height;
cout << "Please input the base of the triangle ";
cin >> base;
trianglearea = (height * base) / 2;
cout << "The area of the Triangle is " << trianglearea << "\n";
break;
}
TY, I made the changes, I like that it saves 6 lines of code as well. And it does work for the determining if I want to run another query. TY.
However, when I run it, it asks for which of the areas I want to solve for, and no matter what I pick, it still runs through all 4 Starting at number 1
Would a Break Command stop after it ran one of them? and should the 'Float area' be instead an 'int area'?