fork download
  1. #include <iostream> //Allows cout/cin
  2. #include <ctime> //Allows time
  3. #include <iomanip> //Allows setprecision
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. //Include header
  10.  
  11. //Input variables
  12. double widgetStores;
  13. double numberSoldFirst1;
  14. double numberSoldFirst2;
  15. double numberSoldSecond1;
  16. double numberSoldSecond2;
  17. double widgetsLeftS1W2;
  18. double widgetsLeftS2W1;
  19. double widgetsLeftS2W2;
  20.  
  21. //Start Clock
  22. clock_t begin, end;
  23. double time_spent;
  24. begin = clock();
  25.  
  26. //Prompt for total number in stores
  27.  
  28. cout << "Total number of widgets at each store starting with :";
  29. cin >> widgetStores;
  30.  
  31. double widgetStore1=widgetStores;
  32. double widgetStore2=widgetStores;
  33. double widgetsLeftS1W1;
  34.  
  35.  
  36. //Prompt for amount sold during first and second week
  37.  
  38. cout << "How many widgets were sold at Store 1 the first week? ";
  39. cin >> numberSoldFirst1;
  40. cout << "How many widgets were sold at Store 1 the 2nd week? ";
  41. cin >> numberSoldSecond1;
  42. cout << "How many widgets were sold at Store 2 the first week? ";
  43. cin >> numberSoldFirst2;
  44. cout << "How many widgets were sold at Store 2 the 2nd week? ";
  45. cin >> numberSoldSecond2;
  46.  
  47. //Calculate Number of widgets
  48. widgetsLeftS1W1-=(widgetStore1-numberSoldFirst1);
  49. widgetsLeftS1W2-=(numberSoldFirst1-numberSoldSecond1);
  50. widgetsLeftS2W1-=(widgetStore2-numberSoldFirst2);
  51. widgetsLeftS2W2-=(numberSoldFirst2-numberSoldSecond2);
  52.  
  53. //Display Values
  54. cout << "Store 1 has " << widgetsLeftS1W2 << " widgets left after the 2nd week.";
  55. cout << "Store 2 has " <<widgetsLeftS2W2 << " widgets left after the 2nd week.";
  56.  
  57. //Show time elapsed
  58. end = clock();
  59. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  60. cout << setprecision(2) << fixed << "****Elapsed time:" <<time_spent/60 << "minutes****";
  61. return 0;
  62. }
Success #stdin #stdout 0s 3476KB
stdin
15
1
0
5
10
stdout
Total number of widgets at each store starting with :How many widgets were sold at Store 1 the first week? How many widgets were sold at Store 1 the 2nd week? How many widgets were sold at Store 2 the first week? How many widgets were sold at Store 2 the 2nd week? Store 1 has -1 widgets left after the 2nd week.Store 2 has 5 widgets left after the 2nd week.****Elapsed time:0.00minutes****