Ceng198
Introduction to Computer Programming
Grading Lab#2
Sections 1
and 2.
“Guessing Game”
Write a program in order to play the game
“Game of Guessing”. Your program should generate a random number and the user
should try to figure out that number. According to the users guess, the program
should also direct the user, such as; if the user guesses a number less than
the computers number the program should warn the user with a message as; “Too
low, a little bit higher please”. And when the user finds the number the
program should print the number of tries that the user did to find the number.
Sample Run: (Let’s say the computer generates a
number: 55)
I
have a number, try to guess it: 43
Too
low, a little bit higher please: 70
Too
high, a little bit lower please: 60
Too
high, a little bit lower please: 50
Too
low, a little bit higher please: 55
You
found the number! Congratulations!
Number
of tries = 5
Hint: To generate a random number include the
libraries;
#include<stdlib.h> and #include<time.h>
And add the following code to your
main program;
srand(time(0));
number = rand()%100 (generates a number between 0-99)
Sections 3
and 4.
One large chemical company
pays its salespeople on a commission basis. The salespeople receive $200 per
week plus 8 percent (if he/she sold less then 2500$ worth of chemicals in a
week) or 12 percent (if he/she sold more then 2500$ worth of chemicals in a
week) of their gross sales for that week.
For example, a salesperson
who sells $5000 worth of chemicals in a week receives $200 plus 12 percent of
$5000, or a total of $800.
Develop a complete C program that uses any of the
repetitive structures to input each salesperson’s gross sales for last week and
calculate and display that salesperson’s earnings.
Sample Run:
Enter sales in dollars (-1 to end): 5000
Salary is: $800.00