Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Task - Improving the Calculator | Introduction
Introduction to .NET with C#

bookTask - Improving the Calculator

The code for the calculator which we created in the previous task is given below. Your task is to add checks to ensure proper user input.

  • Add a check to make sure that the user enters appropriate input for the opr variable. The input should not be empty and should only be equal to +, -, / or *. In case of wrong input, it should prompt the user again for entry. Similar to point 1, add checks for first and second. Make sure the user enters a valid number.

There can be multiple ways to do this. As long as it satisfies the condition, it is a valid solution. Ideally there should be 3 separate try-catch statements for the 3 inputs. You can put all the try-catch statements in a single loop, or separate loops, it is up to your preference.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 6

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 2.22

bookTask - Improving the Calculator

Swipe to show menu

The code for the calculator which we created in the previous task is given below. Your task is to add checks to ensure proper user input.

  • Add a check to make sure that the user enters appropriate input for the opr variable. The input should not be empty and should only be equal to +, -, / or *. In case of wrong input, it should prompt the user again for entry. Similar to point 1, add checks for first and second. Make sure the user enters a valid number.

There can be multiple ways to do this. As long as it satisfies the condition, it is a valid solution. Ideally there should be 3 separate try-catch statements for the 3 inputs. You can put all the try-catch statements in a single loop, or separate loops, it is up to your preference.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 6
some-alt