C++ switch Prints daily, weekly, and monthly sales totals.

Description

C++ switch Prints daily, weekly, and monthly sales totals.

#include <iostream>
using namespace std;
#include <stdio.h>
int main()/*  w w w . ja v  a  2 s  .c  o m*/
{
   float daily=12.34;    // Later, these figures
   float weekly=321.65;  // come from a disk file
   float monthly=12345.67; // instead of being assigned as they are here.
   char ans;
   int day;        // Day value to trigger correct case.
   cout << "Is this the end of the month? (Y/N) ";
   cin >> ans;
   if ((ans=='Y') || (ans=='y'))
   {
      day=6;
   }                          // Month value
   else
   {
      cout << "What day number, 1 through 5 (for Mon-Fri)" << " is it? ";
      cin >> day;
   }
   switch (day)
   {
      case (6): printf("The monthly total is %.2f \n",monthly);
      case (5): printf("The weekly total is %.2f \n",weekly);
      default:  printf("The daily total is %.2f \n", daily);
   }
   return 0;
}



PreviousNext

Related