The assignment was as follows: Write a program that inputs two floating-point values from the keyboard and then displays their product.
I directed them to a sample piece of code as follows:
puts("Enter a float, then an int");
scanf( "%f %d", &y, &x);
printf( "\nYou entered %f and %d ", y, x);
I had the students think through each line of the above code so that they understood how this is taking in 2 numbers and printing them back out.
Then I had them consider the following:
Arguments in printf () can be any valid C expression. For example, to print the sum of x and y, you could write:
total = x + y;
You also could write
printf("%d", x + y);
With the above information, they should be able to figure out how to complete the assignment. It was interesting watching them piece together these bits of information from different locations to come up with a complete solution. The students also felt the satisfaction of figuring out the solution on their own, since I gave them hints in the right direction, but they still had to make the connections on their own.