Pencil and Pen Code#include <stdio.h>
#include <stdlib.h> int main() { float pencils = .38; float pens = .5; int num_pencils; int num_pens; printf("Number of pencils bought "); scanf("%d",&num_pencils); printf("Number of pens bought "); scanf("%d",&num_pens); printf("You bought %d Pens for $ %f \n",num_pens,num_pens*pens); printf("You bought %d Pencils for $ %f \n",num_pencils,num_pencils*pencils); float total = num_pencils*pencils+num_pens*pens; printf("Your total cost is $ %f",total); return 0; } |
Pencil and Pen DetailsThis code is designed to let the user enter a number for pencils and pens. The pencils and pens have a set price. The pencils have a value of .38 cents and the pens have a value of .50 cents. After the user enters the amount of pencils and pens the code finds the total price of each item. The code then prints out the prices on the screen. Next it takes the two items and runs them through an equation. The equation takes the two prices and adds them together to give the user the total cost of both items together.
|
Real Time Applications
This code is another example of a calculator type system. This code can be used to build a calculator for shopping purposes or it could be used to build an inventory tracker/value system.