I need Help! I need a quick peer review!

I am currently in a beginners C++ course at my collage. It's an online class and one of the requirements is to have your code peer reviewed (some quick comment or corrections). Nobody has respond on my classes forum and the peer review is due today before midnight.

Could some one please look at these codes and tell me if they looks correct?

The first one is a commission calculator (Input sales price, output commision):

-Less than $100,000: 5% of the sales price

-$100,000 to $300,000 $5,000 + 10% of the amount of the sales price over $100,000

-More than $300,000 $25,000 + 15% of the amount of the sales price over $300,000

---------------------------------------------
The second is an insurance rate calculator (input age and sex, output rate:

25 or younger | Older than 25
Female: 5% more than base rate | Base rate (100)
Male: 10% more than base rate | 7% more than base rate


(Let me know if you need more infor) Thanks in advanced :)
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
#include <iostream>

using namespace std;

///Commision Calculator Program//////////////////////////////
int main()
{
    int selection;

    //sales price variable
    double salesprice;
    cout << "Commision Calculator \n\n";
    cout << "Enter Item Sales Price \n";
    cin >> salesprice;
    cout << "Sales Price: " << salesprice << endl;
    cout << "Commision: ";
    ///calculate commission///

    if (salesprice < 100000)
    {
        cout << salesprice*.05 << endl;

    }
    else if (salesprice >= 100000 && salesprice<= 300000)
    {
        cout << 5000 + (salesprice*.1) << endl;

    }
    else
    {
        cout << 25000 + (salesprice*.15) << endl;

    }

    cout <<"\n Quit? (1)Yes  (2)NO \n";
    cin >> selection;
    if (selection == 1)
    {
        return 0;
    }
    else
    {
        main();
    }
    return 1;
}


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

using namespace std;

///Insurance Calculator Program//////////////////////////////
int main()
{
    int selection;
    int age;
    char sex;
    int baserate = 100;
    double rate;

    cout << "insurance Calculator \n\n";
    cout << "Enter Age: ";
    cin >> age;
    cout << "\nEnter Sex(m/f): ";
    cin >> sex;
    if (sex != 'm' && sex != 'f')
    {
        main();   //re-boot if wrong characters
    }
///Calculate///////
    cout << "\n\nYour Insurance Rate is...\n" << "$";;
    if (age > 25)
    {
        switch (sex)
        {
        case 'm':
            rate = .07;
            break;
        case 'f':
            rate = 0;
            break;
        }
    }
    else
    {
        switch (sex)
        {
        case 'm':
            rate = .10;

            break;
        case 'f':
            rate = .05;

            break;
        }
    }
    cout << baserate+(baserate*rate);
    /////////////////
    cout <<"\n Quit? (1)Yes  (2)NO \n";
    cin >> selection;
    if (selection == 1)
    {
        return 0;
    }
    else
    {
        main();
    }
    return 1;
}
Last edited on
Recursively calling main is not legal behavior by the standard.
If you need to be able to restart the program at run-time, you should use a loop
http://www.cplusplus.com/doc/tutorial/control/

...or if you want the easy way out, define another function such as "main2" called originally by main, and make main2 call itself recursively instead.


Other than that, both programs seem to run fine. (edit: Didn't see you updated your post with the rules, so not sure yet)
_________________
-$100,000 to $300,000 $5,000 + 10% of the amount of the sales price over $100,000

This isn't what your first "else if" is doing. You'd have to subtract 100,000 somewhere in there and then multiply the difference by 10%
Last edited on
Topic archived. No new replies allowed.