Homework 2: User Input and Output

Wednesday, February 08, 2012     


[Up] [Previous Homework] [Next Homework]


For homework 2, please note that to use scanf with a double, you need to use "%lf", not just "%f". The compiler will complain with warning: format ‘%f’ expects type ‘float *’, but argument 2 has type ‘double *’

An example of how to correctly read in a double is then:

double value;
scanf("%lf", &value);

Complete the following:

  1. Use your cw03.c from the classwork as a starting point
  2. Create a new file called hw02.c
  3. Modify the program to take 4 doubles as input from the user
  4. Modify the program to display both the average and the total sum of the four numbers
  5. Create a script of you compiling and then running your program 3 times, with different input each time.
  6. Once you are done, use submit to submit two files, hw02.c and typescript

    linux3[1]% submit cs104_sheets hw02 hw02.c typescript