A Sample Program
Once again, you begin with a sample program. As before, you'll find some unfamiliar wrinkles that we'll soon iron out for you. The program's general intent should be clear, so try compiling and running the source code shown in Listing 3.1. To save time, you can omit typing the comments.
Listing 3.1 The goldyou.c program.
/* goldyou.c -- the worth of your weight in gold */ #include <stdio.h> int main(void) { float weight; /* user weight */ float value; /* user's gold equivalent */ printf("Are you worth your weight in gold?\n"); printf("Let's check it out.\n"); printf("Please enter your weight in pounds: "); /* get input from the user */ scanf("%f", &weight); /* assume gold is $320 per ounce */ /* 14.5833 converts pounds avd. ... |
Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.