O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 rhodium.c Program
 /* rhodium.c -- your weight in rhodium */ #include <stdio.h> int main(void) { float weight; /* user weight */ float value; /* rhodium equivalent */ printf("Are you worth your weight in rhodium?\n"); printf("Let's check it out.\n"); printf("Please enter your weight in pounds: "); /* get input from the user */ scanf("%f", &weight); /* assume platinum is $2000 per ounce */ /* 14.5833 converts pounds avd. to ounces ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required