C++ Selections example:

By: Nicholas Duchon


// File: ensemble.cpp
// Date: Aug 4, 2014
// Author: Nicholas Duchon
// Purpose: demonstrate a way to select an ensemble
//    using if/else and switch structures

#include <iostream>
using namespace std;

int main () {
   char shirt, pants, shoes;
   double cost = 0;
  
   cout << "Shirt selection from: a, b, c" << endl;
   cout << "Pants selection from: p, q, r" << endl;
   cout << "Shoes selection from: x, y, z" << endl;
   cout << "enter selections for shirt, pants, and shoes: ";
   cin >> shirt >> pants >> shoes;
  
   // using if's:
   if (shirt == 'a') cost = cost + 10;
   if (shirt == 'b') cost = cost + 20;
   if (shirt == 'c') cost = cost + 40;
  
   // using if/else if:
   if (pants == 'p')      cost = cost +  33.50;
   else if (pants == 'q') cost = cost +  75.50;
   else if (pants == 'r') cost = cost + 135.50;
  
   // using switch
   switch (shoes) {
      case 'x': cost = cost +  25; break;
      case 'y': cost = cost +  35; break;
      case 'z': cost = cost + 145; break;
      default : cost = cost +  75;
   } // end switch
  
   cout << "Your selections: " << shirt << pants << shoes << endl;
   printf ("Total cost is: $%.2f\n", cost);
  
   cout << "bye" << endl;
} // end main