fork download
  1. // Andres Guzman CSC5 Chapter 7, P. 444, #3
  2. /******************************************************************************
  3.  *
  4.  * REPORT SALSAS
  5.  * ____________________________________________________________________________
  6.  * Progam will track salsas and report the total amount of jars sold and
  7.  * determine the best and worst selling salsas
  8.  *
  9.  * Computation:
  10.  *
  11.  * jars[i] >(<) highest(lowest)
  12.  * ____________________________________________________________________________
  13.  *
  14.  * INPUT
  15.  * [SIZE] = Array size
  16.  * salsa[SIZE] = Initialization List for salsas
  17.  * jars[SIZE] = Allows for inputs to enter subscript
  18.  *
  19.  * OUTPUT
  20.  *
  21.  * totalsales = Accumulated inputs total of sales
  22.  *
  23.  ******************************************************************************/
  24. #include <iostream>
  25. #include <string>
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. const int SIZE = 5; //Array Size
  31. //Initiialization List of salsa
  32. string salsa[SIZE] = {"Mild", "Medium", "Sweet", "Hot", "Zesty"};
  33. int jars[SIZE]; //Subscript for jars input value
  34. int i; //Counter to cycle to through subscripts
  35. int totalsales = 0; //Accumulator for total sales of jars
  36. //
  37. //Initializing For Loop
  38. for(i = 0; i < SIZE; i++)
  39. {
  40. cout << salsa[i] << " Salsa Jars Sold: ";
  41. cin >> jars[i]; //Input sold jars
  42. while(jars[i] < 0) //Input Validation
  43. {
  44. cout << "Invalid Sales Amount, Please try again." << endl;
  45. cout << salsa[i] << " Salsa Jars Sold: ";
  46. cin >> jars[i];
  47. }
  48. totalsales += jars[i]; //Adds jar input to accumulator
  49. cout << endl;
  50. }
  51. //Initializing For Loop to cycle through subscript
  52. for(i = 0; i < SIZE; i++)
  53. cout << "Jars of " << salsa[i] << " sold: " << jars[i] << "\n";
  54. cout << "Total Sales of Salsas: " << totalsales << endl;
  55. //Creating variables
  56. int highest = jars[0]; //Assigns highest value to subscript [0]
  57. int lowest = jars[0]; //Assigns lowst value to subscript [0]
  58. //
  59. //Initializing For Loop to assign highest and lowest values
  60. for(i = 0; i < SIZE; i++)
  61. {
  62. if(jars[i] > highest) //Determines highest sales
  63. highest = jars[i]; //Assigns highest variable to subscript
  64. if(jars[i] < lowest) //Determines lowest sales
  65. lowest = jars[i]; //Assigns lowest variable to subscript
  66. }
  67. //
  68. //Initializing For Loop
  69. for(i = 0; i < SIZE; i++)
  70. {
  71. if(jars[i] == highest) //When it cycles to the sub that is highest
  72. cout << "Highest Seller: " << salsa[i] << endl;
  73. if(jars[i] == lowest) //When it cycles to the sub that is lowest
  74. cout << "Lowest Seller: " << salsa[i] << endl;
  75. }
  76. return 0;
  77. }
Success #stdin #stdout 0s 5320KB
stdin
1 2 3 4 5
stdout
Mild Salsa Jars Sold: 
Medium Salsa Jars Sold: 
Sweet Salsa Jars Sold: 
Hot Salsa Jars Sold: 
Zesty Salsa Jars Sold: 
Jars of Mild sold: 1
Jars of Medium sold: 2
Jars of Sweet sold: 3
Jars of Hot sold: 4
Jars of Zesty sold: 5
Total Sales of Salsas: 15
Lowest Seller: Mild
Highest Seller: Zesty