2430 : Introduction to Programming in C

Operators and Data Types

Today you will get back your first quiz, and have a second quiz.
After that we will cover the five basic built-in operators in C, + - * / %. They are used for mathematical additions, subtractions, multiplications, divisions and modulus.
Remember the precedence of the operators.
  1. ( )
  2. * / %
  3. + -
Classwork program #1
Write a program that finds the average of three test scores (67.3, 23, 3) and outputs it on the screen without decimal points.
My solution:
#include <stdio.h>

int main()
{
	int answer = (67.3 + 23 + 3)/3;
	printf("Average score: %d\n", answer);
}
Classwork program #2
Write a program that finds the area of Bigi’s cool hat: (Assume Bigi from ear to ear is 7 inches long) Hat height is 7 inches.

Capturing user inputs
Use the GetInteger() and GetReal() functions to handle user inputs from keyboard, as you've read in your textbook. GetInteger() is for int's and long's, and GetReal() is for float's and double's. Some examples of how to use them:
int a;
float b;
a = GetInteger();
b = GetReal();
In order to use these functions, you will need to #include the simpio.h library. Instead of doing:

#include "simpio.h"

You will have to use this, as this library is not on our system by default:

#include "/home/cc/atdp4/su04/staff/atdp4-rc/inc/simpio.h"

Note that when you have done this, you don't need to include genlib.h anymore, because simpio.h already includes it.
Classwork program #3
Write a program that finds the area of Bigi's cool hat, this time asking Bigi (user input) for the his ear to ear length and hat height.
Classwork program #4
Write a program that finds the area of Bigi's friend's cool hat, this time asking Bigi (user input) for the his friend's name as well as his/her ear to ear length and hat height.

Homework Assignment
First, finish classwork program #4 if you haven't yet in class.
Then, write a program that calculates the average of three test scores. For the first two test scores use the scores you received in your quizzes. For the last test score let the user input the amount he/she thinks will receive on their next quiz.
Ex.  Your first quiz score was 12.
     Your second quiz score was 13.
     What do you think you will get on your third quiz?
     %
     The average of your three quiz scores is ?? !!!
Bonus: Ask the user for his/her name and output it at the end.