Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,538 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,521 people online right now. Registration is fast and FREE... Join Now!




Menu Driven Program

 
Reply to this topicStart new topic

Menu Driven Program

GJO87
29 Oct, 2007 - 09:57 AM
Post #1

New D.I.C Head
*

Joined: 29 Oct, 2007
Posts: 3


My Contributions
Write a menu driven program that allows you a contractor to estimate the cost of building a house. The program should ask the user for the following information: number of rooms, size of each room, style of each rooms (all rooms do not have to have same style). Styles: 1 = Standard, 2 = Deluxe, 3 = Superior. The following values are used for costs: Standard = $122 sq/ft, Deluxe = $199 sq/ft, Superior = $299 sq/ft.

Display the cost of each room and total cost of the house.

Allow for multiple houses to be prices.

I think I'm going in the right direction, but I'm having trouble pricing multiple rooms and houses. Did I take the right approach for this problem?

CODE

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
const float STANDARD = 122.00;
const float DELUXE = 199.00;
const float SUPERIOR = 299.00;
void main ()
{
        int choice, length, width, area, cost;
        cout << fixed << showpoint << setprecision(2);

        do
        {
                cout << "\n\t\tHouse Pricing Menu\n\n";
                cout << "1. Standard style room\n";
                cout << "2. Deluxe style room\n";
                cout << "3. Superior style room\n";
                cout << "4. Quit the Program\n\n";
                cout << "Enter your choice: ";
                cin >> choice;
        while (choice < 1 || choice > 4)
        {
                cout << "Please enter 1, 2, 3, or 4: ";
                cin >> choice;
        }
        if (choice !=4)
        {
                cout << "Please enter length of room in feet: ";
                cin >> length;
                cout << "Please enter width of room in feet: ";
                cin >> width;
                area = length * width;
                cout << "The area of the room is: " << area << endl;
        }
        switch (choice)
        {
                case 1: cost = area * STANDARD;
                        break;
                case 2: cost = area * DELUXE;
                        break;
                case 3: cost = area * SUPERIOR;
                        break;
        }
        cout << "The total cost of the room is $";
        cout << cost << endl;
        } while (choice !=4);
}



User is offlineProfile CardPM
+Quote Post

Pontus
RE: Menu Driven Program
29 Oct, 2007 - 10:18 AM
Post #2

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
My Contributions
Your code is very goood but for more then 1 room u should do this:
CODE
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
const float STANDARD = 122.00;
const float DELUXE = 199.00;
const float SUPERIOR = 299.00;
int main ()
{
        int choice, length, width, area=0, cost,nr_rooms;//area = 0 is important because we will use the += operator
        cout << fixed << showpoint << setprecision(2);

        do
        {
                cout << "\n\t\tHouse Pricing Menu\n\n";
                cout << "1. Standard style room\n";
                cout << "2. Deluxe style room\n";
                cout << "3. Superior style room\n";
                cout << "4. Quit the Program\n\n";
                cout << "Enter your choice: ";
                cin >> choice;
        while (choice < 1 || choice > 4)
        {
                cout << "Please enter 1, 2, 3, or 4: ";
                cin >> choice;
        }
        do
       {
        cout<<"How many rooms do u want?"<<endl;
        cin>>nr_rooms;
        }
        while(nr_rooms<=0);
        if (choice !=4)
        {
               for(int a=0;a<nr_rooms;a++)
               {
                 cout << "Please enter length of room nr."<<a+1<<" in feet: ";
                 cin >> length;
                 cout << "Please enter width of room nr."<<a+1<<"  in feet: ";
                 cin >> width;
                 area += length * width;
                 cout << "The area of theroom nr."<<a+1<<"   is: " << area << endl;
                }
        }
        switch (choice)
        {
                case 1: cost = area * STANDARD;
                        break;
                case 2: cost = area * DELUXE;
                        break;
                case 3: cost = area * SUPERIOR;
                        break;
        }
        cout << "The total cost of the room is $";
        cout << cost << endl;
        } while (choice !=4);
}


This post has been edited by manhaeve5: 29 Oct, 2007 - 10:21 AM
User is offlineProfile CardPM
+Quote Post

chuck87
RE: Menu Driven Program
29 Oct, 2007 - 10:42 AM
Post #3

D.I.C Head
**

Joined: 7 Sep, 2007
Posts: 65


My Contributions
First make the includes like this
CODE

#include <iostream>
#include <iomanip>


Include <conio.h> is not necessary

Before main add this too
CODE

using namespace std;

see http://forums.devshed.com/c-programming-42...mean-45679.html if you want to check how st works

Multiplying area with STANDARD means you multiply an integer with a float.That's wrong so declare area and cost as float

Lastly make main like this
CODE

int main()


and add return 0; after
CODE

} while (choice !=4);


This post has been edited by chuck87: 29 Oct, 2007 - 10:43 AM
User is offlineProfile CardPM
+Quote Post

GJO87
RE: Menu Driven Program
29 Oct, 2007 - 03:14 PM
Post #4

New D.I.C Head
*

Joined: 29 Oct, 2007
Posts: 3


My Contributions
Thanks to those who have replied. Both of you have helped. However, I am still having trouble displaying the cost of each room. Also, all rooms do not have to be the same style. For example, a house can have 3 rooms, but one of each. I don't think my program does that.
User is offlineProfile CardPM
+Quote Post

GJO87
RE: Menu Driven Program
29 Oct, 2007 - 04:41 PM
Post #5

New D.I.C Head
*

Joined: 29 Oct, 2007
Posts: 3


My Contributions
QUOTE(manhaeve5 @ 29 Oct, 2007 - 11:18 AM) *

Your code is very goood but for more then 1 room u should do this:
CODE
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
const float STANDARD = 122.00;
const float DELUXE = 199.00;
const float SUPERIOR = 299.00;
int main ()
{
        int choice, length, width, area=0, cost,nr_rooms;//area = 0 is important because we will use the += operator
        cout << fixed << showpoint << setprecision(2);

        do
        {
                cout << "\n\t\tHouse Pricing Menu\n\n";
                cout << "1. Standard style room\n";
                cout << "2. Deluxe style room\n";
                cout << "3. Superior style room\n";
                cout << "4. Quit the Program\n\n";
                cout << "Enter your choice: ";
                cin >> choice;
        while (choice < 1 || choice > 4)
        {
                cout << "Please enter 1, 2, 3, or 4: ";
                cin >> choice;
        }
        do
       {
        cout<<"How many rooms do u want?"<<endl;
        cin>>nr_rooms;
        }
        while(nr_rooms<=0);
        if (choice !=4)
        {
               for(int a=0;a<nr_rooms;a++)
               {
                 cout << "Please enter length of room nr."<<a+1<<" in feet: ";
                 cin >> length;
                 cout << "Please enter width of room nr."<<a+1<<"  in feet: ";
                 cin >> width;
                 area += length * width;
                 cout << "The area of theroom nr."<<a+1<<"   is: " << area << endl;
                }
        }
        switch (choice)
        {
                case 1: cost = area * STANDARD;
                        break;
                case 2: cost = area * DELUXE;
                        break;
                case 3: cost = area * SUPERIOR;
                        break;
        }
        cout << "The total cost of the room is $";
        cout << cost << endl;
        } while (choice !=4);
}



If you have more than one room, the area of the previous room is added. For example, if the area of the first room is 16 and the are of the second room is 25 then the displayed area of room to will be 41.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month