Advertisement
pushrbx

Untitled

Feb 1st, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. // TestB.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. const int NUMCARS = 8;
  9.  
  10. struct Car
  11. {
  12.     int fuelType;
  13.     double price;
  14. };
  15.  
  16. int CalculateTax(int fuelType);
  17.  
  18. int main()
  19. {
  20.     double totalCarCost = 0;
  21.  
  22.     Car cars[NUMCARS] = {
  23.         {0, 10000},
  24.         {2, 8500},
  25.         {0, 22000},
  26.         {1, 14000},
  27.         {1, 37000},
  28.         {2, 18900},
  29.         {1, 28000},
  30.         {0, 45000}
  31.     };
  32.  
  33.     cout << "Car Price \t Fuel Type \t Tax" << endl;
  34.  
  35.     for(int i = 0; i < NUMCARS; i++)
  36.     {
  37.         Car car = cars[i];
  38.         int tax = CalculateTax(car.fuelType);
  39.  
  40.         cout << car.price << "\t\t" << car.fuelType << "\t\t" << tax << endl;
  41.         totalCarCost += car.price;
  42.     }
  43.  
  44.     cout << "Total car cost = " << totalCarCost << endl;
  45.  
  46.     return 0;
  47. }
  48.  
  49. int CalculateTax(int fuelType)
  50. {
  51.     switch(fuelType)
  52.     {
  53.     case 0:
  54.         return 50;
  55.     case 1:
  56.         return 60;
  57.     default:
  58.         return 0;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement