Help me win!

closed account (3pk1T05o)
My friend and I made a small bet of who could do a program. I have no clue how to complete this, please help!
Haverly’s Needs a program to calculate the area of a room depending on the shape of the room. The Program should output a menu asking the shape of the room as follows:
Haverly’s
Room
Calculator:
************************
1.Square Room
2. Rectangular Room
3. Round Room
4. Quit Please enter a menu item(1-4)
>
If the user enters a 1, then the program should ask the user the
Width of the room. If the user enters a 2, then the program should ask for the length and the width of the room. If the user enters a 3, the program should ask for the radius. Use the following formulas:

Area of a rectangle or square:
Area = length*width;

Area of circle
(r = radius):
Area =3.14*r^2

If the user enters a 4, the program should output a
Message saying,
“Thank You for using Haverly’s Room Calculator...” And exit the program.

Input Validation: The Program must check to see if the user enters a valid number, i.e. 1 Through 4, When selecting an item from the menu. If The user does not enter a valid menu item, display an error message and exit the program. For length, width or radius the program should not accept any values less than or equal to zero. If An invalid value is entered, display an error message and exit the program.
.
Last edited on
closed account (3pk1T05o)
Sent
That would be cheating, you wouldn't cheat your friend would you ?
Is your friend also the teacher of your intro to programming class?
closed account (3pk1T05o)
No, she found this problem on google.
closed account (3pk1T05o)
and she does this for a job, i'm a beginner and have no clue. and youtube wont help
Sounds like your going to loose a bet since I can't find that question on google... Why don't you give it a try and show us what you can do...
Here's the code that fits your needs (compiled and tested):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>

void menu(unsigned short int &CalcOption)
{
	std::cout << "Haverly's\nRoom\nCalculator\n******************\n";
	std::cout <<
		"1. Square Room\n2. Rectangular Room\n3. Round Room\n4. Quit\n\nPlease enter a menu item(1-4)\n> ";
	std::cin >> CalcOption;
}

void getSquareRoomArea(long double &Area, long double &Width)
{
	std::cout << "\nEnter width of square room: ";
	std::cin >> Width;
	if (!(Width > 0))
	{
		goto error;
	}
	Area = Width * Width;
	std::cout << "\nArea of square room: " << Area;
  error:
	if (!(Width > 0))
	{
		std::cout << "\nError... ";
	}
}

void getRectangularRoomArea(long double &Area, long double &Length, long double &Width)
{
	std::cout << "\nEnter length and width of rectangular room\n";
	std::cout << "Length: ";
	std::cin >> Length;
	if (!(Length > 0))
	{
		goto error;
	}
	std::cout << "Width: ";
	std::cin >> Width;
	if (!(Width > 0))
	{
		goto error;
	}
	Area = Length * Width;
	std::cout << "\nArea of rectangular room: " << Area;
  error:
	if ((!(Length > 0)) || (!(Width > 0)))
	{
		std::cout << "\nError... ";
	}
}

void getRoundRoomArea(long double &Area, long double &Radius, const float &PI)
{
	std::cout << "\nEnter radius of round room: ";
	std::cin >> Radius;
	if (!(Radius > 0))
	{
		goto error;
	}
	Area = PI * (Radius * Radius);
	std::cout << "\nArea of round room: " << Area;
  error:
	if (!(Radius > 0))
	{
		std::cout << "\nError... ";
	}
}

void calculate(const unsigned short int &CalcOption, long double &Area, const float &PI)
{
	long double Length, Width, Radius;
	switch (CalcOption)
	{
	case 1:
		getSquareRoomArea(Area, Width);
		break;
	case 2:
		getRectangularRoomArea(Area, Length, Width);
		break;
	case 3:
		getRoundRoomArea(Area, Radius, PI);
		break;
	case 4:
		std::cout << "\nThank You for using Haverly's Room Calculator... ";
		break;
	}
}

int main()
{
	const float PI{3.14};
	long double Area;
	unsigned short int CalcOption;
	menu(CalcOption);
	if (!((CalcOption > 0) && (CalcOption < 5)))
	{
		std::cout << "\nError... ";
		goto end;
	}
	calculate(CalcOption, Area, PI);
  end:
	return 0;
}


P.S. What's the reward for the winner?
Last edited on
closed account (3pk1T05o)
It didn't work, I came up with this but can't figure out how to finish:
#include <iostream>
using namespace std;

int main()
{
cout << "Haverly's Room Calculator: \n";

cout << "************************** \n";
cout << endl;
cout << "1. Square room\n";
cout << "2. Rectangular Room\n";
cout << "3. Round Room\n";
cout << "4. Quit\n";
cout << endl << endl;
cout << "Please enter a menu item(1-4)> \n";



return 0;
}
@boost lexical cast
It is advisable that you refrain from using uniform initialization especially when you want to help others. Some people may not have a C++ compiler that supports C++11 features. They can either say it does not compile or it does not work (they are both the same).

Edit : There are also a number of problems in your code.
Last edited on
Topic archived. No new replies allowed.