C - Calculate the total revenue for the quarter and output it

Introduction

%ld tells the compiler that it is to use a long conversion for the output of this value.

Demo

#include <stdio.h>

int main(void)
{
      const float Revenue_Per_150 = 4.5f;
      unsigned short sales1 =23500;                           // Stock sold in January
      unsigned short sales2 =19300;                           // Stock sold in February
      unsigned short sales3 =21600;                           // Stock sold in March
      float  total = 0.0f;                                // Sales for the quarter

      unsigned long QuarterSold = sales1 + sales2 + sales3; // Calculate quarterly total

      // Output monthly sales and total for the quarter
      printf("Stock sold in\n Jan: %d\n Feb: %d\n Mar: %d\n", sales1, sales2, sales3);
      printf("Total stock sold in first quarter: %ld\n", QuarterSold);

      // Calculate the total revenue for the quarter and output it
      total = QuarterSold/150*Revenue_Per_150;
      printf("Sales revenue this quarter is:$%.2f\n", total);
      return 0;//from  www  . ja va  2  s . co m
}

Result

Related Topic