08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3 ■ Programs with Sequence Logic

}

printf("Reserved price and tickets sold? ");

scanf("%lf %d", &rPrice, &rTickets);

rSales = rPrice * rTickets;

printf("Stands price and tickets sold? ");

scanf("%lf %d", &sPrice, &sTickets);

sSales = sPrice * sTickets;

printf("Grounds price and tickets sold? ");

scanf("%lf %d", &gPrice, &gTickets);

gSales = gPrice * gTickets;

tTickets = rTickets + sTickets + gTickets;

tSales = rSales + sSales + gSales;

printf("\nReserved sales: $%3.2f\n", rSales);

printf("Stands sales: $%3.2f\n", sSales);

printf("Grounds sales: $%3.2f\n", gSales);

printf("\n%d tickets were sold\n", tTickets);

printf("Total money collected: $%3.2f\n", tSales);

Exercises 3

1. For each of the following, give examples of data that will be read correctly and

examples of data that will cause the program to crash. Assume the declaration

int i, j; double x, y;);

(a) scanf("%d %d", &i, &j);

(b) scanf("%lf %lf", &x, &y);

(c) scanf("%d %lf %d", &i, &x, &j);

2. For 1(c), state what will be stored in i, x, and j for each of the following sets

of data:

(a) 14 11 52

(b) -7 2.3 52

(c) 0 6.1 7.0

(d) 1.0 8 -1

3. Write a program that requests a user to enter a weight in kilograms, and converts it

to pounds. (1 kilogram = 2.2 pounds.)

4. Write a program that requests a length in centimeters and converts it to inches.

(1 inch = 2.54 cm.)

61

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!