pastebin

Paste Search Dynamic
Recent pastes
donuts
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int preferredDonut(int list[], int size);
  8.  
  9. int main()
  10. {
  11.         //declarations for the arrays and various other needed items
  12.         int numberOfDonuts;
  13.         string* donuts;
  14.         int* votes;
  15.         int summedvotes = 0;
  16.         int r = 0;
  17.  
  18.        
  19.         //getting the number of donut types in question
  20.         cout << "Please enter the number of donuts types.\n";
  21.         cin >> numberOfDonuts;
  22.         cout << "\n";
  23.  
  24.         //using the input to create the arrays that will be used
  25.         donuts = new string[numberOfDonuts];
  26.         votes = new int[numberOfDonuts];
  27.  
  28.         //output for what information we want entered
  29.         cout << "Please enter the type of donut followed by the number of votes it recieved.\n";
  30.  
  31.         //collecting input
  32.         for (r = 0; r < numberOfDonuts; r++)
  33.         {
  34.                 cin >> donuts[r] >> votes[r];
  35.         }
  36.  
  37.         //summing votes, needed later for the percentage
  38.         for (r = 0; r < numberOfDonuts; r++)
  39.                 summedvotes += votes[r];
  40.  
  41.         //outputting vote results
  42.         printf("%10s %10s %10s\n","Donut","Votes","Percentage");
  43.         for (r = 0; r < numberOfDonuts; r++)
  44.         {
  45.                 printf("%10s %10d %10.2f\n", string(donuts[r]), votes[r], (votes[r]/double(summedvotes))*100);
  46.         }
  47.  
  48. }
Parsed in 0.009 seconds