Mega Code Archive

 
Categories / C / Code Snippets
 

Choosing the correct type long

/* Choosing the correct type: short */ #include <stdio.h> void main() { const float per = 4.5f; short x = 16165; short y = 18905; short z = 12139; float revenue = 0.0f; long total = x+y+z; /* Calculate quarterly total */ /* Output monthly sales and total for the quarter */ printf("\n x: %d\n y: %d\n z: %d",x,y,z); printf("\n Total: %ld",total); /* Calculate the total revenue and output it */ revenue = total/150*per; printf("\nSales revenue is:$%.2f\n",revenue); }