fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH7 HW question 3
  2. /*****************************************************************************
  3.  *
  4.  * Chips and Salsa
  5.  *
  6.  *********************
  7.  *
  8.  * This program uses two parallel arrays to track
  9.  * sales of five salsa types. It displays the sales for each type, the total
  10.  * sales, and the highest and lowest selling salsa.
  11.  *
  12.  * **********
  13.  * INPUT
  14.  * Number of jars sold for each salsa type
  15.  *
  16.  * OUTPUT
  17.  * Sales for each type, total sales, highest seller, lowest seller
  18.  ****************************************************************************/
  19.  
  20. #include <iostream>
  21. #include <string>
  22. using namespace std;
  23.  
  24. const int SIZE = 5;
  25.  
  26. int main()
  27. {
  28. string names[SIZE] = {"mild", "medium", "sweet", "hot", "zesty"};
  29. int jars[SIZE];
  30. int total = 0;
  31. int high = 0;
  32. int low = 0;
  33.  
  34. // Input (no negative numbers allowed)
  35. for (int i = 0; i < SIZE; i++)
  36. {
  37. cout << "Enter jars sold for " << names[i] << ": ";
  38. cin >> jars[i];
  39. while (jars[i] < 0)
  40. {
  41. cout << "Cannot be negative. Re-enter: ";
  42. cin >> jars[i];
  43. }
  44. }
  45.  
  46. // Add up the total and find the highest and lowest sellers
  47. for (int i = 0; i < SIZE; i++)
  48. {
  49. total = total + jars[i];
  50. if (jars[i] > jars[high])
  51. high = i;
  52. if (jars[i] < jars[low])
  53. low = i;
  54. }
  55.  
  56. // Output
  57. cout << "\nSales Report\n";
  58. for (int i = 0; i < SIZE; i++)
  59. cout << names[i] << ": " << jars[i] << " jars" << endl;
  60. cout << "Total sales: " << total << " jars" << endl;
  61. cout << "Highest selling: " << names[high] << endl;
  62. cout << "Lowest selling: " << names[low] << endl;
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter jars sold for mild: Enter jars sold for medium: Enter jars sold for sweet: Enter jars sold for hot: Enter jars sold for zesty: 
Sales Report
mild: 0 jars
medium: 0 jars
sweet: 1793203640 jars
hot: 5278 jars
zesty: 1793203640 jars
Total sales: -708554738 jars
Highest selling: sweet
Lowest selling: mild