Need help with this (functions, mainly). I'm stuck!

I've gone as far as I can go because I just absolutely hit a dead end. I don't know what to set the return to in the double GetMarkupPrice(double dMSRP, int nDays) function.

Anyway, this is the code I've done thus far:

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>

using namespace std;

void SetupConsole(void);
void GetUserInput(int &nDays, int &nShipType);
double GetBasePrice(int nShipType);
double GetMarkupPrice(double dMSRP, int nDays);
void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType);

int main()
{
    int nDays;
    int nShipType;

    SetupConsole();
    GetUserInput(nDays, nShipType);
}

void SetupConsole(void)
    {
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
    }

void GetUserInput(int &nDays, int &nShipType)
    {
        cout << "Hello, welcome to the automated ship building system";
    cout << "brought to you by Clay and Class Inc. What type of";
    cout << "ship do you want?" << endl << endl;

    cout << "1) Frigate" << endl;
    cout << "2) Container" << endl;
    cout << "3) Fishing" << endl;
    cout << "4) Weather" << endl;

    cout << "Ship selection: ";
    cin >> nShipType;

        while (nShipType >= 5)
            {
                cout << "Ship selection: ";
                cin >> nShipType;
            }

            if (nShipType == 1)
                {
                    cout << "You chose a frigate ship!" << endl;
                }

            else if (nShipType == 2)
                {
                    cout << "You chose a container ship!" << endl;
                }

            else if (nShipType == 3)
                {
                    cout << "You chose a fishing ship!" << endl;
                }

            else if (nShipType == 4)
                {
                    cout << "You chose a weather ship!" << endl;
                }

    cout << "Enter the number of days until the deadline: ";
    cin >> nDays;

        while (nDays < 90)
            {
                cout << "Sorry, can't do that! Try asking";
                cout << "something more reasonable." << endl;

                cout << "Enter the number of days until the deadline: ";
                cin >> nDays;
            }

        if (nDays >= 90)
            {
                return;
            }
    }

double GetBasePrice(int nShipType)
    {
        if (nShipType == 1)
                {
                    return 100000;
                }

        else if (nShipType == 2)
                {
                    return 500000;
                }

        else if (nShipType == 3)
                {
                    return 350000;
                }

        else if (nShipType == 4)
                {
                    return 600000;
                }
    }

double GetMarkupPrice(double dMSRP, int nDays)
    {
        if (nDays >= 90 && nDays <= 180)
                {
                    return;
                }

        else if (nDays > 180 && nDays < 240)
                {
                    return;
                }

        else if (nDays >= 240 && nDays <= 360)
                {
                    return;
                }

        else if (nDays > 360)
                {
                    return;
                }
    }

void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType)
    {

    }


The directions for this assignment are these:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Your task is to create
a program that will ask the user for a time line in days that they want a ship made,
the size of the ship: (1)frigate, (2)container ship, (3)fishing ship, (4)weather ship, 
and tell them how much it will cost. Each ship costs a little different:

Frigates should cost $100,000
Container ships should cost $500,000
Fishing ships should cost $350,000
Weather ships should cost $600,000

If they require the ship to be built in less than 90 days, it simply can't be done.
If they require the ship to be built in less than 180 days, you have to charge them 
twice the rate for normal ship building. 
If they require the ship to be built in less than 240 days, you have to charge them
50% more. 
If they ask to build the chip in between 240 and 360 days you will charge them the normal 
going rate based on the ship type. 
Any amount greater than 360 days should deduct 15% total from the price of the ship. 


So, for double GetMarkupPrice(double dMSRP, int nDays); I have to return an equation. The problem is that I don't know how to return the equations I need it to. Help, please?

Edit: This is what the console should look like once done:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Hello, welcome to the automated ship building system brought to you by 
Clay and Class Inc. What type of ship do you want?

1) Frigate
2) Container
3) Fishing
4) Weather

Ship Selection: 3

You chose a Fishing Ship!

Enter the number of days until the deadline: 5

Sorry, can't do that, try asking something more reasonable.
Enter the number of days until the deadline: 10

Sorry, can't do that, try asking something more reasonable.
Enter the number of days until the deadline: 90

Here is the calculated cost for a Fishing ship.
Maximum Days of Labor:                    90
Base Price Per Ship $:             350000.00
Mark Up Price       $:             700000.00
Last edited on
Instead of doing this
1
2
3
4
5
6
7
8
9
10
11
12
13
while (nDays < 90)
            {
                cout << "Sorry, can't do that! Try asking";
                cout << "something more reasonable." << endl;

                cout << "Enter the number of days until the deadline: ";
                cin >> nDays;
            }

        if (nDays >= 90)
            {
                return;
            }


It would be better to have getMarkupPrice return -1 if nDays is less then or equal to 90. Otherwise, you would return 2*msrp for less then 180, 1.5*msrp for less then 240, return msrp for between 240 and 360, and return .85*msrp for more then 360
I got everything to work perfectly, except for one thing:

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <iostream>
#include <iomanip>

using namespace std;

void SetupConsole(void);
void GetUserInput(int &nDays, int &nShipType);
double GetBasePrice(int nShipType);
double GetMarkupPrice(double dMSRP, int nDays);
void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType);

int main()
{
    int nDays;
    int nShipType;

    SetupConsole();
    GetUserInput(nDays, nShipType);
    double dMSRP = GetBasePrice(nShipType);
    double dMarkUpPrice = GetMarkupPrice(dMSRP, nDays);
    DisplayResult(dMSRP, dMarkUpPrice, nDays, nShipType);


}

void SetupConsole(void)
    {
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
    }

void GetUserInput(int &nDays, int &nShipType)
    {
        cout << "Hello, welcome to the automated ship building system";
    cout << "brought to you by Clay and Class Inc. What type of";
    cout << "ship do you want?" << endl << endl;

    cout << "1) Frigate" << endl;
    cout << "2) Container" << endl;
    cout << "3) Fishing" << endl;
    cout << "4) Weather" << endl;

    cout << "Ship selection: ";
    cin >> nShipType;

        while (nShipType >= 5)
            {
                cout << "Ship selection: ";
                cin >> nShipType;
            }

            if (nShipType == 1)
                {
                    cout << "You chose a frigate ship!" << endl;
                }

            else if (nShipType == 2)
                {
                    cout << "You chose a container ship!" << endl;
                }

            else if (nShipType == 3)
                {
                    cout << "You chose a fishing ship!" << endl;
                }

            else if (nShipType == 4)
                {
                    cout << "You chose a weather ship!" << endl;
                }

    cout << "Enter the number of days until the deadline: ";
    cin >> nDays;

        while (nDays < 90)
            {
                cout << "Sorry, can't do that! Try asking";
                cout << "something more reasonable." << endl;

                cout << "Enter the number of days until the deadline: ";
                cin >> nDays;
            }

        if (nDays >= 90)
            {
                return;
            }
    }

double GetBasePrice(int nShipType)
    {
        if (nShipType == 1)
                {
                    return 100000;
                }

        else if (nShipType == 2)
                {
                    return 500000;
                }

        else if (nShipType == 3)
                {
                    return 350000;
                }

        else if (nShipType == 4)
                {
                    return 600000;
                }
    }

double GetMarkupPrice(double dMSRP, int nDays)
    {
        if (nDays < 90)
                {
                    return(-1);
                }

        else if (nDays < 180)
                {
                    return(2 * dMSRP);
                }

        else if (nDays < 240)
                {
                    return(1.5 * dMSRP);
                }

        else if (nDays <= 360)
                {
                    return(dMSRP);
                }

        else if (nDays > 360)
                {
                    return(.85 * dMSRP);
                }
    }

void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType)
    {
        if (nShipType == 1)
                {
                    cout << "frigate" << endl;
                }

            else if (nShipType == 2)
                {
                    cout << "container" << endl;
                }

            else if (nShipType == 3)
                {
                    cout << "fishing" << endl;
                }

            else if (nShipType == 4)
                {
                    cout << "weather" << endl;
                }

        cout << "Here is the calculated cost for a ";
        cout << nShipType << " ship." << endl;

        cout << "Maximum days of labor: " << setw(22) << nDays << endl;

        cout << "Base price per ship $: " << setw(22) << dMSRP << endl;
        cout << "Mark up price       $: " << setw(22) << dMarkupPrice << endl;

        cout << "Please send your check to Clay and Class Inc, ";
        cout << "5150 Rich St.";
    }


In the console, it's displaying:
Here is the calculated cost for a 3 ship.
Instead of having it display:
Here is the calculated cost for a Fishing ship.

How can I change it to display the actual name of the type of ship the user has purchased, instead of the number of the ship the user has purchased?

Edit: nevermind, I was being stupid!
Last edited on
Topic archived. No new replies allowed.