fork download
  1. //Nathan Dominguez CSC5 Chapter 7, P.444 , #3
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Reprot Salsa Sales
  6.  * _____________________________________________________________________________
  7.  * This program reports and displays the sales for five different salsas.
  8.  *
  9.  * Computation is based on the formula:
  10.  * total sales = mild sales + medium sales + sweet sales + hot sales
  11.  * + zesty sales
  12.  *
  13.  * _____________________________________________________________________________
  14.  * INPUT
  15.  * jarsSold : Amount of jars sold for each salsa
  16.  *
  17.  * OUTPUT
  18.  * jars[] : Individual sales
  19.  * totalSales : Total sales of all salsas
  20.  * salsas[] : Displays highest and lowest selling salsas
  21.  *
  22.  **************************************************************/
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <string>
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. //Array List
  31. string salsas[5] = {"Mild", "Medium", "Sweet", "Hot", "Zesty"};
  32. int jars[5]; //INPUT - jars sold
  33. int totalSales = 0; //How many jars were sold in total
  34. int leastSold; //VALIDATE - assign a name to the least amount of
  35. //jars sold
  36. int mostSold; //VALIDATE - assign a name to the most amount of
  37. //jars sold
  38. int mostSalsa; //OUTPUT - name of highest selling salsa
  39. int leastSalsa; //OUTPUT - name of lowest selling salsa
  40. //
  41. //loop program 5 times
  42. for (int i = 0; i < 5; i++)
  43. {
  44. cout << "Enter number of jars sold for " << salsas[i] << ":" << endl;
  45. cin >> jars[i];
  46. //
  47. //input validation for jars sold
  48. if ( jars[i] < 0)
  49. {
  50. cout << "Error, enter a value greater than 0." << endl;
  51. cout << "Enter number of jars sold for " << salsas[i] << ".";
  52. cout << endl;
  53. cin >> jars[i];
  54. }
  55. totalSales += jars[i];
  56. }
  57. leastSold = jars[0];
  58. //input validation for most and least jars sold
  59. for (int i = 0; i < 5; i++)
  60. {
  61. if (jars[i] > mostSold)
  62. {
  63. mostSold = jars[i];
  64. mostSalsa = i;
  65. }
  66. if (jars[i] < leastSold)
  67. {
  68. leastSold = jars[i];
  69. leastSalsa = i;
  70. }
  71. }
  72. //output sales report
  73. cout << "\t\t Sales Report" << endl;
  74. for (int i = 0; i < 5; i++)
  75. {
  76. cout << salsas[i] << ".................." << jars[i] << " jars sold";
  77. cout << endl;
  78. }
  79. cout << "Total.................." << totalSales << " jars sold" << endl;
  80. cout << salsas[mostSalsa] << " was the highest selling salsa." << endl;
  81. cout << salsas[leastSalsa] << " was the lowest selling salsa." << endl;
  82. return 0;
  83. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
6
7
2
9
stdout
Enter number of jars sold for Mild:
Enter number of jars sold for Medium:
Enter number of jars sold for Sweet:
Enter number of jars sold for Hot:
Enter number of jars sold for Zesty:
		 Sales Report
Mild..................5 jars sold
Medium..................6 jars sold
Sweet..................7 jars sold
Hot..................2 jars sold
Zesty..................9 jars sold
Total..................29 jars sold
Zesty was the highest selling salsa.
Hot was the lowest selling salsa.