passable?

Pages: 12
Is this passable?

Write the following program: The user is asked to enter 2 floating point numbers (use doubles). The user is then asked to enter one of the following mathematical symbols: +, -, *, or /. The program computes the answer on the two numbers the user entered and prints the results. If the user enters an invalid symbol, the program should print nothing.

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

double ask_user_input()
{
    double input{0};
    std::cin >> input;
    return input;
}

void ask_user_operator(double first_input, double second_input)
{
    int user_operator{0};
    std::cin >> user_operator;
    if(user_operator == 1)
        std::cout << first_input + second_input;

    else if(user_operator == 2)
        std::cout << first_input - second_input;

    else if(user_operator == 3)
        std::cout << first_input * second_input;

    else if(user_operator == 4)
        std::cout << first_input / second_input;

    else
        std::cout << "please only put either 1,2,3,4 \n";

}
int main()
{
    std::cout << "Pick first number please: \n";
    double first_input;
    first_input = ask_user_input();
    std::cout << "Pick second number please: \n";
    double second_input;
    second_input = ask_user_input();
    std::cout << "Pick 1 for +: \n" << "Pick 2 for -: \n" << "Pick 3 for *: \n" << "Pick 4 for /: \n";
    ask_user_operator(first_input, second_input);

    return 0;
}
Hello soulworld05,

That would depend on what you consider passable?

From the view point of the code working it does most of the time.

From the view point of being able to read the code I would call it a fail.

In the "main" function if you wrote this for the compiler then the compiler thanks you because it has less work to do.

If you expect some one to read this you missed.

There is a time an place for a menu, but this is not 1 of them.

When entering an operator the variable should be defined as a char and the input should be (+, -, *, /).

Inside the "ask_user_operator" function it would be very easy to change this to deal with a "char" variable and still achieve the same results.

In the utopia of school, where no one makes any mistakes a divide by zero would never happen, but you should still deal with "second_input" being zero or maybe less than zero.

Just to give you an idea:
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
#include <iostream>

double ask_user_input()
{
    double input{ 0 };
    std::cin >> input;
    return input;
}

void ask_user_operator(double first_input, double second_input)
{
    int user_operator{ 0 };

    std::cin >> user_operator;

    if (user_operator == 1)
        std::cout << first_input + second_input;

    else if (user_operator == 2)
        std::cout << first_input - second_input;

    else if (user_operator == 3)
        std::cout << first_input * second_input;

    else if (user_operator == 4)
        std::cout << first_input / second_input;

    else
        std::cout << "please only put either 1,2,3,4 \n";

}
int main()
{
    std::cout << "Pick first number please: ";  // <--- leave out the "\n". Puts your input on the same line.

    double first_input;

    first_input = ask_user_input();

    std::cout << "Pick second number please: ";  // <--- leave out the "\n".

    double second_input;

    second_input = ask_user_input();

    std::cout << 
        "Pick 1 for +: \n"
        "Pick 2 for -: \n"
        "Pick 3 for *: \n"
        "Pick 4 for /: \n";

    ask_user_operator(first_input, second_input);

	// A fair C++ replacement for "system("pause")". Or a way to pause the program.
	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue: ";
	std::cin.get();

	return 0;  // <--- Not required, but makes a good break point.
}


To give you an idea of what your output could look like:

Pick first number please: 10
Pick second number please: 20

Pick 1 for +:
Pick 2 for -:
Pick 3 for *:
Pick 4 for /:
 Enter choice: 1

10 + 20 = 30

 Press Enter to continue:



Another option could be:

Pick first number please: 10
Pick second number please: 20

Enter operator (+, -, *, /): +

10 + 20 = 30

 Press Enter to continue:



Something to think about.

Andy
I haven't learn std::cin.ignore and std::numberic_limit::streamsize>::max()

Maybe this is why I couldn't do anything else.

Do you mean to say, My coding is a bit hard to read? Should I separate them more. I was thinking of making new function that do evaluation and print.

I have one more quiz to do. The math is not my thing. I had to look up how that math work. But I will post it tomorrow. I have to sleep, by morning I will write the code and also fix the previous code, the one u helped.
Last edited on
Yep, a bit of simple whitespace makes it a bit easier to read.

I've made a few suggestions - any others depend upon what's expected of you in class.

Your program dumps the user out after one sample which is OK and meets the spec, but it depends on whether you need to provide code that does that gracefully or the way it happens with your code.

It might be a trick or generality but the assignment talks about floating point numbers. Your choice of double is correct but maybe they want float's instead.

Overall, you effort is more than passable for a beginner in a non-major subject, if I have that right, so I'd give you 8/10+ and definitely none of this fail business for a couple of lousy but nevertheless important blank lines.

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

double ask_user_input()
{
    double input{0};
    std::cin >> input;
    return input;
}

void ask_user_operator(double first_input, double second_input)
{
    int user_operator{0};
    std::cin >> user_operator;
    
    if(user_operator == 1)
        std::cout << first_input + second_input;
    
    else if(user_operator == 2)
        std::cout << first_input - second_input;
    
    else if(user_operator == 3)
        std::cout << first_input * second_input;
    
    else if(user_operator == 4)
    {
        if(second_input == 0)
            std::cout << "ERROR -> DIVISION BY ZERO\n";
        else
            std::cout << first_input / second_input;
    }
    
    else
        std::cout << "please only put either 1,2,3,4 \n";
    
}
int main()
{
    std::cout << "Pick first number please: "; // <--
    double first_input;
    first_input = ask_user_input();
    
    std::cout << "Pick second number please: "; // <--
    double second_input;
    second_input = ask_user_input();
    
    std::cout
    << "Pick 1 for +: \n" << "Pick 2 for -: \n"
    << "Pick 3 for *: \n" << "Pick 4 for /: \n"; // <-- KEEP LINEWIDTH < 80
    
    ask_user_operator(first_input, second_input);
    
    return 0;
}

Definitely a pass, but there's a couple of problems if you want the A. One of my teachers was a stickler for following the directions to the letter. I see two points where he might give you a knock off.
The user is then asked to enter one of the following mathematical symbols: +, -, *, or /.

So it appears that he does want to be able to enter the char '+' and you are supposed to then use nested if statements to discern which symbol was pressed and get the right action done. None of this "1 for +" business.

If the user enters an invalid symbol, the program should print nothing

So saying "std::cout << "please only put either 1,2,3,4 \n";" might actually be a point off.

Setting up the ask_user_input function was a fun idea, but the name of ask_user_operator gets cluttered when it actually does more than what the name implies. Overall I like that you're showing initiative in creating functions, but they also aren't saving you any lines of code typed, and might actually be making the code a bit harder to read. No points taken away, but none really added either.

Again, it all comes down to how strict your teacher is on this, which is hard to know ahead of time on your first assignment.


The user is asked to enter 2 floating point numbers (use doubles).

So using doubles is correct.


Something that you might find unexpected: College teachers often like to be asked questions. Go to his office several days before the assignment is due and ask if the code you're submitting fits the bill. You'll get a clearer picture of what he wants and you will be able to fix the code before actually submitting it. Teachers often have their office hours written on their syllabus. They are required to be available to students during that time, and it gets boring just staring at the wall as the time ticks by.

This is much preferable to getting the right answer on a board like this, especially because if you copy and paste from here it is easy to find and you might be caught on plagiarism. Build a relationship with a real human being and keep your assignments off the internet.

Edit: removed a person's name from a single line in this post and clarified by adding "So using doubles is correct"
Last edited on
@newbeig

A switch - case structure with a default, among other even better alternatives is a much better/clearer/maintainable alternative to nested if's and other inexpert and incomplete inventories. But this might be well beyond @OP's experience/wish or capability.

In so far as your other patronizing passive-aggressive and otherwise inane comments directed at me, even to the extent of your stupidity about real-humanity, I direct you to go and fuck yourself. You wouldn't know anything about real humans if one jumped up and bit you. And the same goes for your knowledge of university teaching or computing. Your main expertise as demonstrated here and elsewher is in being an absolute and un-constructive fuckwit. I feel sorry for you that your whole life is a waste of aimless protein - your father's contribution especially.

An extra point is defining a variable and then in a separate statement assigning a value. A variable should always be initialised when it is defined - either to a default value (eg 0 for int) or to a required value. Hence:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    std::cout << "Pick first number please: "; // <--
    double first_input = ask_user_input();
    
    std::cout << "Pick second number please: "; // <--
    double second_input = ask_user_input();
    
    std::cout
    << "Pick 1 for +: \n" << "Pick 2 for -: \n"
    << "Pick 3 for *: \n" << "Pick 4 for /: \n"; // <-- KEEP LINEWIDTH < 80
    
    ask_user_operator(first_input, second_input);
    
    return 0;
}


Have you covered const variables yet? If yes, then first_input and second_input can be defined as const.

Also, a function normally just does one thing. ask_user_operator() actually does 3 things - obtains the operator, performs the calculation and displays the result. What about if the result was needed to be used in another calculation? I'd suggest that ask_user_operator() (if that name is kept) returns the calculated value and the function caller either uses it or displays it as needed.
Last edited on
Hello soulworld05,

Sorry about that. I did not mean to leave those lines in the code. That is just something I use to pause the screen of the console window before it closes when the program ends.

The "std::cin.ignore()" function just clears the input buffer of whatever might be left from a previous input. If the input buffer is empty then it acts like a pause waiting for you to press enter to ignore it and continue.

That fancy part of the first parameter just comes up with a very large number to use. This should be the size of what the input buffer was defined as. The second parameter is optional and can be changed if needed. The default for the second parameter is "\n".

You could just as easily write "std::cin.ignore(1000)" or "std::cin.ignore(1000, '\n')" or even make the first parameter "10000". The idea here is a large number that is likely to be more than what would normally be entered.

As the comment says just include the header file <limits> and it should work fine. If you do not need it take it out.

A nice part of C and C++ is that you do not have to know everything at first just how to use it.


Do you mean to say, My coding is a bit hard to read? Should I separate them more.


Yes and yes.

When writing the source code the first goal is to make it easy to read and follow. The first benefit is to you when it comes time to go over what you have done and second to anyone else who has to read it.

The compiler does not care about white space, i.e., if(user_operator == 1) could be written as if(user_operator==1), and the compiler would not care. It would compile either version the same.

When you compare:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{
    std::cout << "Pick first number please: \n";
    double first_input;
    first_input = ask_user_input();
    std::cout << "Pick second number please: \n";
    double second_input;
    second_input = ask_user_input();
    std::cout << "Pick 1 for +: \n" << "Pick 2 for -: \n" << "Pick 3 for *: \n" << "Pick 4 for /: \n";
    ask_user_operator(first_input, second_input);

    return 0;
}

and
int main()
{
    std::cout << "Pick first number please: ";  // <--- leave out the "\n". Puts your input on the same line.

    double first_input;

    first_input = ask_user_input();

    std::cout << "Pick second number please: ";  // <--- leave out the "\n".

    double second_input;

    second_input = ask_user_input();

    std::cout << 
        "Pick 1 for +: \n"
        "Pick 2 for -: \n"
        "Pick 3 for *: \n"
        "Pick 4 for /: \n";

    ask_user_operator(first_input, second_input);

    return 0;  // <--- Not required, but makes a good break point.
}

You decide. Which one is easier to read.

As it has been mentioned it is ALWAYS a GOOD idea to initialize your variables when defined. If for no other reason than to know that it does not contain a garbage value.

I see that you have used this in the function "ask_user_input()" double input{0};. This tells me that you are using at least the C++11 standards or later.

The "{0}" is fine, but if the {}s are empty the compiler will initialize the variable to the needed type of (0) zero based on how the variable is defined. In the case of initializing a double to be proper it should be { 0.0 } although { 0 } does work, but I would not count on it as compilers and header files are different and what works in 1 may not work in another.

In "main" you have the code:
1
2
3
4
5
std::cout << 
    "Pick 1 for +: \n"
    "Pick 2 for -: \n"
    "Pick 3 for *: \n"
    "Pick 4 for /: \n";

First this should be in the "ask_user_operator" function where it is the only place it is used. Just makes more sense. As a menu this way of writing the "cout" makes it easier to visualize what the output will be, but this should not be a menu just a statement of what symbols can be used.

Since each line is a string you do not need the insertion operator (<<) to chain everything together.

Just something small to make life easier.

In the function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void ask_user_operator(double first_input, double second_input)
{
    char user_operator{};

    //std::cout <<  // <--- Should not be a menu.
    //    "Pick 1 for +: \n"
    //    "Pick 2 for -: \n"
    //    "Pick 3 for *: \n"
    //    "Pick 4 for /: \n";

    std::cout << "Enter operator (+, -, *, /): ";
    std::cin >> user_operator;

    if (user_operator == '+')
        //std::cout << first_input + second_input;
        std::cout << "\n" << first_input << " + " << second_input << " = " << first_input + second_input;

Just a thought to consider. Based on your instructions. Changing the "std::cout" statements in the if statements makes the output look nicer than printing just a number with nothing to say what it is for.


Pick first number please: 100
Pick second number please: 200
Enter operator (+, -, *, /): +

100 + 200 = 300

 Press Enter to continue:


Andy
Hello soulworld05,

newbieg wrote:

Setting up the ask_user_input function was a fun idea, but the name of ask_user_operator gets cluttered when it actually does more than what the name implies.


I agree with this, but would add that a function should do 1 thing. I would consider calling the function "ask_for_operator" because that is what it should do and nothing more.

I put the "if" statements and "cout" statements in a print function which is only called if the operator is valid. This is in "main" because it follows the directions.
1
2
if(user_operator)
    PrintOutput(first_input, second_input, user_operator);


The function now looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
char ask_for_operator()
{
    char user_operator{};

    //do
    //{
        std::cout << "Enter operator (+, -, *, /): ";
        std::cin >> user_operator;

        if (user_operator != '+' && user_operator != '-' && user_operator != '*' && user_operator != '/')
        {
            std::cerr << "\n     Please only put either (+, -, *, /) \n";  // <--- Changed to "cerr".

            user_operator = '\0';
        }

    //} while (user_operator != '+' && user_operator != '-' && user_operator != '*' && user_operator != '/');

    return user_operator;
}

I left the do/while loop as an idea, but it does not comply with the instructions.

Based on some of the examples this may not be the best way to do this, but it should be inline with what you know right now. Better to understand the basics first than the advanced examples.

Andy
Is this improved form the previous coding?

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

double ask_user_input()
{
    double input{0};

    std::cin >> input;

    return input;
}

char ask_user_operator()
{
    char get_operator{0};

    std::cin >> get_operator;

    return get_operator;

}

void print_input(int first_input, char get_operator, int second_input)
{

    if(get_operator == '+')
        std::cout << first_input << " + " << second_input << " = " << first_input + second_input;

    else if(get_operator == '-')
        std::cout << first_input << " - " << second_input << " = " << first_input - second_input;

    else if(get_operator == '*')
        std::cout << first_input << " * " << second_input << " = " << first_input * second_input;

    else if(get_operator == '/')
        std::cout << first_input << " / " << second_input << " = " << first_input / second_input;
}

int main()
{
    std::cout << "Pick first number please: ";

    double first_input;

    first_input = ask_user_input();

    std::cout << "Pick second number please: ";

    double second_input;

    second_input = ask_user_input();

    std::cout << '\n';
    std::cout << '\n';

    std::cout << "Now we have " << first_input << " and " << second_input << " \n";

    std::cout << '\n';
    std::cout << "Please pick + . - , * , / : ";

    char get_operator;

    get_operator = ask_user_operator();

    std::cout << '\n';

    print_input(first_input, get_operator, second_input);

    return 0;
}
Last edited on
 
if (get_operator == +)


+ needs to be specified as a char using '

 
if (get_operator == '+')


Same for the other operators.

But

1
2
3
4
5
6
std::cout <<

		"Pick 1 for +: \n"
		"Pick 2 for -: \n"
		"Pick 3 for *: \n"
		"Pick 4 for /: \n";


asks for a number to be entered when the symbol should be entered.

1
2
3
std::cout << "Enter operator (* / + -): ";

char get_operator {ask_user_operator()};


You might also want to display a message if an unknown operator is entered.

1
2
3
4
else if (get_operator == '/')
		std::cout << first_input / second_input;
	else
		std::cout << "Unknown operator\n";

Last edited on
Hello soulworld05,

Since I have seen your post you have edited it twice. DO NOT do that it makes seeplus's response hard to understand when your code appears to be right.

It is better to respond with a new post to show your changes then every thing fits together better.

Lines 57 and 58 should be the prompt in the function "ask_user_operator" not in "main".

The variable "get_operator" is misleading. it makes one think that you are going to get something when in actuality it is receiving something from the function. "operator" is enough to suffice.

I have not tested this revised code, but it looks like it fulfills the requirements and should work.

Andy
I'm so sorry, seem like the comment update really slow. For me I didn't see anybody post even after I adjust it severely time. I'll re-post the newer below the edit so everybody can see the new re coding.

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

double ask_user_input()
{
    double input{0};

    std::cin >> input;

    return input;
}

char ask_user_operator()
{
    char get_operator{0};

    std::cin >> get_operator;

    return get_operator;

}

void print_input(int first_input, char get_operator, int second_input)
{

    if(get_operator == '+')
        std::cout << first_input << " + " << second_input << " = " << first_input + second_input;

    else if(get_operator == '-')
        std::cout << first_input << " - " << second_input << " = " << first_input - second_input;

    else if(get_operator == '*')
        std::cout << first_input << " * " << second_input << " = " << first_input * second_input;

    else if(get_operator == '/')
        std::cout << first_input << " / " << second_input << " = " << first_input / second_input;
}

int main()
{
    std::cout << "Pick first number please: ";

    double first_input;

    first_input = ask_user_input();

    std::cout << "Pick second number please: ";

    double second_input;

    second_input = ask_user_input();

    std::cout << '\n';
    std::cout << '\n';

    std::cout << "Now we have " << first_input << " and " << second_input << " \n";

    std::cout << '\n';
    std::cout << "Please pick + . - , * , / : ";

    char get_operator;

    get_operator = ask_user_operator();

    std::cout << '\n';

    print_input(first_input, get_operator, second_input);

    return 0;
}
Last edited on
Hello soulworld05,

When I first compiled the program I did get 1 warning.

in "main" you call the function with: print_input(first_input, get_operator, second_input);.

But the function definition is: void print_input(int first_input, char get_operator, int second_input).

This may work, but sending a "double" and receiving an "int" means the the decimal portion of the "double" will be dropped to fit the number in an "int".

Keep line 55 if yo want. IMO it just duplicates the input that you can still see and since there is no way to change the input.

To me you enter an operator and the print function is called. If there is no operator match the function prints nothing and returns to "main" where the program ends without knowing that there was any kind of error.

My thoughts for now.

Andy
Thank you, I totally forget about double. As seeplus suggest use const. I tried to add const but it seem to give even more error. How do I properly add? Seem like I need to add const to initialized. So I added const on line 3 and 5. I somehow think its wrong.

const double input{0}?
No, you're modifying 'input' via cin >> input, so the input variable should not be const (lines 3 and 5).

What seeplus was saying is that instead of
1
2
3
double first_input;

first_input = ask_user_input();

You can do
 
double first_input = ask_user_input();


and then,
 
const double first_input = ask_user_input();
which tells the reader of the code that first_input will not be modified for the rest of its existence.

It's not essential to the code; just a suggestion.
Last edited on
It DOES look much short and clear now. I added const in operator too.

Thank so much for helping me. There are too many thing to remember at same time. Sometime I missed small and simple.

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

double ask_user_input()
{
    double input{0};

    std::cin >> input;

    return input;
}

char ask_user_operator()
{
    char get_operator{0};

    std::cin >> get_operator;

    return get_operator;

}

void print_input(double first_input, char the_operator, double second_input)
{

    if(the_operator == '+')
        std::cout << first_input << " + " << second_input << " = " << first_input + second_input;

    else if(the_operator == '-')
        std::cout << first_input << " - " << second_input << " = " << first_input - second_input;

    else if(the_operator == '*')
        std::cout << first_input << " * " << second_input << " = " << first_input * second_input;

    else if(the_operator == '/')
        std::cout << first_input << " / " << second_input << " = " << first_input / second_input;

    else
        std::cout << "Error input, Please follow the direction.";
}

int main()
{
    std::cout << "Pick first number please: ";

    const double first_input = ask_user_input();

    std::cout << "Pick second number please: ";

    const double second_input = ask_user_input();

    std::cout << '\n';
    std::cout << '\n';

    std::cout << "Now we have " << first_input << " and " << second_input << " \n";

    std::cout << '\n';
    std::cout << "Please pick + . - , * , / : ";

    const char the_operator = ask_user_operator();

    std::cout << '\n';

    print_input(first_input, the_operator, second_input);

    return 0;
}
Last edited on
Hello soulworld05,

On lines 3 and 5 by making the variable "const" you are saying that this variable can not be changed, but you then use it in the "cin" statement which flags an error.

Your "print" function would look like this:
void print_input(const double first_input, const char get_operator, const double second_input).

This is more a safe guard to say that these variables can not be changed just used. It does have a better use if you pass a variable by reference.

Try this change in the function definition and see what happens. If you get an error post the complete error message.

Andy
Ok this is I think the final code. Thank all ^ ^

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

double ask_user_input()
{
    double input{0};

    std::cin >> input;

    return input;
}

char ask_user_operator()
{
    char get_operator{0};

    std::cin >> get_operator;

    return get_operator;

}

void print_input(const double first_input, const char the_operator, const double second_input)
{

    if(the_operator == '+')
        std::cout << first_input << " + " << second_input << " = " << first_input + second_input;

    else if(the_operator == '-')
        std::cout << first_input << " - " << second_input << " = " << first_input - second_input;

    else if(the_operator == '*')
        std::cout << first_input << " * " << second_input << " = " << first_input * second_input;

    else if(the_operator == '/')
        std::cout << first_input << " / " << second_input << " = " << first_input / second_input;

    else
        std::cout << "Error input, Please follow the direction.";
}

int main()
{
    std::cout << "Pick first number please: ";

    const double first_input = ask_user_input();

    std::cout << "Pick second number please: ";

    const double second_input = ask_user_input();

    std::cout << '\n';
    std::cout << '\n';

    std::cout << "Now we have " << first_input << " and " << second_input << " \n";

    std::cout << '\n';
    std::cout << "Please pick + . - , * , / : ";

    const char the_operator = ask_user_operator();

    std::cout << '\n';

    print_input(first_input, the_operator, second_input);

    return 0;
}
Last edited on
Hello soulworld05,

Lines 45 and 49 do not need the "const", but since the program only runs once it really does not matter unless the compiler has a problem with it.

Otherwise it looks like it should do what you need.

Andy
Pages: 12