I will be honest i have no clue where to begin with this code. I need some help with this code.
Design and implement the areas.cpp program (skeleton give so that it correctly meets the program
specifications given below.
Specifications:
Create a menu-driven program that finds and displays
areas of 3 different objects.
The menu should have the following 4 choices:
1 -- square
2 -- circle
3 -- right triangle
4 -- quit
• If the user selects choice 1, the program should
find the area of a square.
• If the user selects choice 2, the program should
find the area of a circle.
• If the user selects choice 3, the program should
find the area of a right triangle.
• If the user selects choice 4, the program should
quit without doing anything.
• If the user selects anything else (i.e., an invalid
choice) an appropriate error message should be
printed.
Sample Run
Program to calculate areas of objects
1 -- square
2 -- circle
3 -- right triangle
4 -- quit
2
Radius of the circle: 3.0
Area = 28.2743
In a while loop, cout the menu options and accept a char as input (cin). If it's 4, terminate the program. If the input is 1-3, call the appropriate function to perform the calculation they asked for. Get the measurement with another cin>>some_float_var;
So i just use this program? Were do i fill in the blanks? I know i have to add the radius of a circle into this and the area, but how do i go about doing that?
isn't the area of a square width*length?
That gives the area of a rectangle. A square is a special case of a rectangle where height and width are the same.
#include<iostream>
usingnamespace std;
int main()
{
char choice;
do{
std::cout << "Please choose from the choices listed.";
std::cout << "1 --Area of a square\n";
std::cout << "2 -- Area of a circle\n";
std::cout << "3 -- Area of a right triangle\n";
std::cout << "4 -- Quit\n";
std::cin >> choice;
if (choice == '1')
float length;
std::cout << "Enter length of square.";
std::cin >> length;
std::cout << "Area of the square =" << length*length << "\n\n";
elseif (choice == '2')
float radius;
std::cout << "Enter the radius of the circle: ";
std::cin >> radius;
area = 3.142 * radius * radius
cout << "Area of a circle is =";
elseif (choice == '3')
std::cout << "Enter the length of the right triangle:";
std::cin >> length;
std::cout << "Enter the width of the right traingle: ";
std::cin >> width;
std::cout << "Area of the right triangle =" << length*width/2 << "\n\n";
} while (choice != '4');
return 0;
}
Your compiler should be telling you what is wrong. Are you looking at its traceback? It's best to ALWAYS post it so we don't have to waste time guessing or running your code.
one error is in line 13 saying that choice is undefined. Another error is in line 6 saying char is is expected ';'. Another error is in line 21 saying the else is suppose to be a expected statement. In line 24 it says area is undefined. Line 25 it says cout is expected a ';' Line 28 it says the else is suppose to be expected statement. Line 35 it says that the word choice is undefined . this is all the errors
#include<iostream>
usingnamespace std;
int main()
{
char choice;
float radius,area,length,width;
do
{
std::cout << "Please choose from the choices listed.";
std::cout << "1 --Area of a square\n";
std::cout << "2 -- Area of a circle\n";
std::cout << "3 -- Area of a right triangle\n";
std::cout << "4 -- Quit\n";
std::cin >> choice;
if (choice == '1')
{
std::cout << "Enter length of square.";
std::cin >> length;
std::cout << "Area of the square =" << length*length << "\n\n";
}
elseif (choice == '2')
{
std::cout << "Enter the radius of the circle: ";
std::cin >> radius;
area = 3.142 * radius * radius;
cout << "Area of a circle is =";
}
elseif (choice == '3')
{
std::cout << "Enter the length of the right triangle:";
std::cin >> length;
std::cout << "Enter the width of the right traingle: ";
std::cin >> width;
std::cout << "Area of the right triangle =" << length*width/2 << "\n\n";
}
} while (choice != '4');
return 0;
}