FontysICT-sem1

Training Guru-calc: variables, operations and conversions: A Console app(lication)

(Concepts: int, double, operations and conversions)

Preparation

Do you know the difference between an int, double and string?

Introduction

We are going to make a working calculator. It’s a minimalist calculator, but it can calculate things for you that you can’t do yourself. How much is 655 times 23623? Most people prefer to use a program for that. You can make that program.

Assignment

We ask the user to type in a number (and press enter), another number (enter again), then we tell the user how much you get when you add the numbers, as well as how much you get when you multiply the numbers.

Some steps explained…

Here C# code showing the concepts discussed above:

Console.WriteLine("Dear user,");
Console.WriteLine("Please type a number (and press enter)");

String textTypedByUser = Console.ReadLine();
Console.WriteLine("You have typed: "+ textTypedByUser);

int numberTypedByUser = Convert.ToInt32(textTypedByUser);

int a = 42;
int b = 365;
int c = a + b;

String answer = Convert.ToString(c);
Console.WriteLine(answer);

It is possible to write this shorter, but keep an eye on whether it remain readable!

With this knowledge, it is possible to create the aforementioned calculator: The user can type in integers. For example, you can choose to tell the tell the user both what the sum and the product of the numbers are.

Did you succeed? Then you have now written yourself a program that can do more than yourself (multiply the numbers 7225 and 5588 within a millisecond, for example) and have taken the first step toward becoming an experienced software engineer.

Stuck? Ask a question of your neighbor! If you can’t figure it out together ask your teacher. In the beginning, this programming can be quite difficult.

If the calculator works then you can program the last 2 requirements. These are:

Maybe you already had it, then you are not only good at programming, but you also passed the analysis phase honorably.

Discuss assignments regularly with your teacher and then enter feedback into Feedpulse.

Extras

To learn it really well, it is good to make extensions to the assignments, and ask for feedback on these as well. This can lead to a higher grade (note: you have to be able to program it yourself, code-copy from the Internet is not enough). Some possible extensions: