Stores twelve months of sales and prints selected ones. - C++ File Stream

C++ examples for File Stream:cin

Description

Stores twelve months of sales and prints selected ones.

Demo Code

#include <iostream>
using namespace std;
#include <ctype.h>
#include <conio.h>
#include <iomanip>
const int NUM = 12;
void main()/* www.  j  a  va2s . c o m*/
{
   float sales[NUM];
   int ctr, ans;
   int req_month;                 // Holds user's request.
   // Fill the array.
   cout << "Please enter the twelve monthly sales values\n";
   for (ctr=0; ctr<NUM; ctr++)
   {
      cout << "What are sales for month number " << ctr+1 << "? \n";
      cin >> sales[ctr];
   }
   cout << "Prints any sales from the last " << NUM << " months\n\n";
   do
   {
      cout << "For what month (1-" << NUM << ") do you want " << "to see a sales value? ";
      cin >> req_month;

      cout << "\nMonth " << req_month << "'s sales are " << setprecision(2) << sales[req_month-1];
      cout << "\nDo you want to see another (Y/N)? ";
      ans=getch();
      ans=toupper(ans);
   } while (ans == 'Y');
   return;
}

Result


Related Tutorials