CS 133 - Assignment 2
50 POINTS
DUE announced in class
Purpose: To become familiar with simple expressions and formatted input/output.Suppose you want to write a program that does simple addition, subtraction, multiplication and division for a seven-year-old child, The following program prompts her/him for two numbers. The program then waits for the user to type an answer. When she/he gives her/his answer, the program displays the correct result, so she can compare with the correct answer.
The program below executes a simple addition problem. Your task is to implement the other three missing functions to subtract, multiply and divide.
The user will only input two numbers for each of the calculations and the output will be basically the same as you see for the addition.
You will separate the output for each section with:
*** Math Practice DIVISION ***, etc.
Some variables will have to be declared as floats, please be aware of the problems that we can encounter when dividing int/int int/float, and other unexpected results by mixing data types.
1) Start the C compiler.
2) Enter the program as shown. (note this is not a runnable program, just a skeleton of what you need to do)
// Filename: math.C
// Program to help children with simple math.
// Your Name, class, term
// Compiler used (in this case was Borland)
// Prompt child for two values after printing
// a title message.#include <stdio.h>
int main()
{int num1_add; // put comments
int num2_add; // put comments
int ans_add; // put comments
int user_ans; // put comments
int correct_add_answer; // put comments... other variables for the program....
printf "This program is a math drill program that will include";
printf "Addition, Subtraction, Multiplication, Division";
printf "You will enter two numbers and the number will be";
printf "evaluated. Please make sure not to type character or";
printf "other symbols. Have fun!";printf "*** Math Practice ADDITION ***\n\n\n";
printf "What is the first number? " ;
scanf num1_add;
printf "What is the second number? ";
scanf num2_add;// Compute answer and give user a chance to
// answer it.ans_add = num1_add + num2_add;
printf "\n What do you think the answer is? ";
scanf user_ans;// Prints answer after a blank line.
printf "\n" num1_ans " plus " num2_ans " is " correct_add_answer "\n\n Hope you got it right!";continue with the rest..........subtraction, multiplication, division
return 0;
}
3) Save the program in a file on your storage device (do this frequently and not just at the end of program entry process).
4) Compile the program (use the compile pull-down menu), then run it.
5) At this point you should try playing with various options provided in the pull-down menus. In particular try to set a few "watches" (Borland) and run the program in step-over mode (Borland).
6) Make sure that you have an opening screen where it explains exactly what the program does. Remember, this is a child and need all the help possible. Also tell the user the range of values they can use and other problems such as 0s in the division section so alert the user about it before entering this number.
partial output:The
*Notes:
A printout of the your program execution
Unfortunately you can not print the entire output using this method, so you will have to do one screen at a time. (we may do this only for the first two assignments to get used to the process)
You must include your full name on every thing you hand in.
You must keep all originals with yourself, just hand in copies.
Hold on to your graded assignments until the end of this term (at least).
Any questions, let me know...