Looping Simple Menu

New to programming, no prior experience and 4 weeks into intro to C++.

Alright.. after trying to solve this all day with the textbook, the internet and by myself, I still can't figure this out.

What I'm trying to accomplish is to ask the user what their floor plan is (in square feet), have them pick what kind of material they want and give them a general price.

Which is working out great so far, but I would also like to add a loop at the end that cycles back if they want to re-do the estimate with a different material selection and if not exit out the program.

I've been trying do while and if/else loops but i can't get them to work right. Any help would be stellar, thanks.

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
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string custName, selection;
    int custNumber, floorSize, material, contactSystem;

//please ignore the non-relevant variables, this program has other parts.


    cout<<"\nWhat are the dimensions of the floor plan in square feet?\n";
    cin>>floorSize;
    cout<<"\nGreat, with this information we can now help you determine \n"
    "a general price for the room in mind.\n";


cout<<"\nWhat kind of flooring are you interested in:\nPlease select 1-4\n";
cout<<"Wood _______ 1\nVinyl ______ 2\nSlate ______ 3\nConcrete ___ 4\n";
cin>>material;


        cin.ignore();
        if (material == 1)
            cout<<"\nAt a median rate of $1.75 a sqft, "
            "\nWood flooring would cost, on average, $" <<1.75*floorSize<<
            " for a floor plan of "<<floorSize<<"sqft.";
        else if (material == 2)
            cout<<"\nAt a median rate of $0.95 a sqft, "
            "\nVinyl flooring would cost, on average, $"<<.95*floorSize<<
            " for a floor plan of "<<floorSize<<"sqft.";
        else if (material == 3)
            cout<<"\nAt a median rate of $2.35 a sqft, "
            "\nSlate flooring would cost, on average, $"<<2.35*floorSize<<
            " for a floor plan of "<<floorSize<<"sqft.";
        else if (material == 4)
            cout<<"\nAt a median rate of $2.13 a sqft, "
            "\nConcrete flooring would cost, on average, $"<<2.13*floorSize<<
            " for a floor plan of "<<floorSize<<"sqft.\n";



        cout<<"\n\nThank you for using our quick quote system, to try a different flooring option, "
        "please select 1 or select 2 to exit.\n";
        cin>>selection;


That's basically what I've come up with so far minus all the erroneous attempts. Though as is I technically complete the assignment, I would like the extra credit from making the last part loop.

Thanks
@karthur13

Here is how I do menus:

http://www.cplusplus.com/forum/beginner/99203/#msg534078


I used a switch, but a series of if-else-if-else is fine too. Switches work on constant integral types, so you could use this. Use if-else for other types.

Note the switch has a default case, if using if's - always provide an else to catch bad input in the same way as a default:

Another thing to consider, is if there is more than a few lines of code in each case (or else if), then put that code into it's own function. This will keep your code tidy, and is a big plus for others who see your code.

Also note: I had a separate function just display the menu.

Hope all goes well :+)
Topic archived. No new replies allowed.