Sie sind auf Seite 1von 6

For each of the following programs, you will use good

programming practices meaning you will:


have appropriate names for your variables
add short, descriptive comments above chunks of code
After each question, call me over to show me. You do not need
to submit them, but do save your work - we might use it in the
future.
Variables: Practice creating, naming and using variables.
1. Variable Practice
Create two variables, an Integer and a String. Output the variables in a MessageBox.
For example:

2. Age, Name, Class


Create a program that responds to the user when they enter their age, their name and
their favourite subject.
For example, when the user enters age:

3. Cheeseburger
Create a program that asks the user how many burgers they want, and then figures out
the cost after taxes.
The price of a cheeseburger is $4.
The tax is 14% (0.14).
total = mealTotal * tax;
Based on what the user inputs, determine the cost and provide appropriate output.

Conditions: Practice using if/else statements with proper


programming practices.
4. Birthday
Create a program that asks for the users age and the year they were born. Using that
information, discover whether or not their birthday has passed yet this year. Produce
output accordingly.

5. Higher or Lower
Create a guessing game (similar to yesterdays assignment). In this game, your program
will generate a random number from 1-100 and the user will have 5 chances to guess
the number. Your program will track the number of guesses, the number of wins and the
number of games the user has played by displaying and updating those stats on the
form.

Using if/else statements, you will tell your user if their guess is higher or lower than the
actual number by displaying an arrow image and updating how many turns the user
has left.
*You may need to declare certain variables in the partial class.

6. Calculator
Create a calculator! You have already created one in the past, but now you will building
off that idea and create something that looks like this:

Some things you will need to know:


a. The char variable is a character variable. It is similar to a String, but it only
stores one character at a time. This is useful when you are storing symbols, such
as the symbols on a calculator (+, -, *, /). You assign characters to a char using
single quotations ( ), and would write it out as:

char operation = +;

b. To turn a String into a Double, you will use Double.TryParse(string, double). You
will need to do this when your program is making calculations (when you hit
Enter). For example, you will have string of the number the user wants to
calculate (operand1), and you need to turn that into a new double variable
(number1).

Double.TryParse(operand1, out number1);


//you need to add out in front of the double.

Examples:

Declare your variables in the partial class.

Adding numbers to the variable input to display in the textBox.

Clearing/emptying your variables.

Using the char variable and assigning the first number to be calculated (saving it for
later).

An example of how to do a calculation and use Double.TryParse().

Das könnte Ihnen auch gefallen