From: levent demirekler <ldemir1@cs.umbc.edu>

To: burt@cs.umbc.edu <burt@cs.umbc.edu>

Subject: project 3 solution

Date: Saturday, April 17, 1999 5:12 PM

Hello,

I think it will be good for students to have the solution of project 3. I am sending you one of the students project. Please put it to your webpage. I also explained how many points they lost from not doing/following something.

Levent

Code solution


/* Filename: proj3.c
Author: xxxxxxxxxx
SSN: -xxxx
Section: xxxx
Description:  This program will ask the user for a number between
		 5 and 15. Then print out the values, the value
		 squared, and the value cubed for the values from 1
              to the number entered by the user.
Input:        The number entered by the user.
Output:       The value, value squared, and value cubed.
Constraints:  Number entered must be between 5 and 15.
Assumptions:  None.
Pseudocode:   Declare variables.
		 Prompt user to enter a number between 5 and 15.
              Check validity of entry.
              Begin to display output.
              Set up a loop to calculate and display values for each 
	             iteration.
*/ 
	
#include <stdio.h>
main()
{
    int i, 
        number, 
        value, 
        value_squared, 
        value_cubed;

    printf("Enter an integer between 5 and 15: ");
    scanf("%d", &number);
 
    /* Check if the number is valid or not, if not ask the user 
       to input the number again*/
    while (number<5 || number>15) 
    {
        printf("\n***Not a valid entry***\n");
        printf(:\nPlease reenter an integer"); 
        printf(" between 5 and 15: ");
        scanf("%d", &number);
    }
 
    /* Print out the value, square and cube of the value */
    printf("Value Square Cube\n");
    for (i = 1; i <= number; i++)
    {
        value = i;	 
        value_squared = i * i;
        value_cubed = i * i * i;
        printf("%3d %3d %4d\n", value, value_squared, value_cubed);
    }
    return 0;
} 
umbc8[2]% cc proj3.c
umbc8[3]% a.out
Enter an integer between 5 and 15: 3
***Not a valid entry***
Please reenter an integer between 5 and 15: 13
Value Square Cube
  1   1    1
  2   4    8
  3   9   27
  4  16   64
  5  25  125
  6  36  216
  7  49  343
  8  64  512
  9  81  729
 10 100 1000
 11 121 1331
 12 144 1728
 13 169 2197
umbc8[4]% exit


Some remarks on project 3 grading: