fork download
  1.  
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10. double totalCosts = 0;
  11.  
  12. // PIZZA
  13.  
  14. cout << "What size is your first pizza?\n"
  15. "small: $8.00\n"
  16. "medium: $10.00\n"
  17. "large: $12.00\n";
  18. string currentSize = "";
  19. getline(cin, currentSize);
  20. cout << "\n";
  21. if(currentSize == "small")
  22. {
  23. totalCosts += 8;
  24. }
  25. else if(currentSize == "medium")
  26. {
  27. totalCosts += 10;
  28. }
  29. else if(currentSize == "large")
  30. {
  31. totalCosts += 12;
  32. }
  33. else
  34. {
  35. cout << "invalid size: " << currentSize;
  36. return 0;
  37. }
  38.  
  39. string pizzaToppings = "";
  40. cout << "Choose from the following toppings:\n"
  41. "onions: $1.00\n"
  42. "peppers: $1.20\n"
  43. "ham: $1.50\n"
  44. "hamburger: $1.25\n"
  45. "pepperoni: $1.55\n"
  46. "salami: $1.63\n"
  47. "sausage: $1.44\n";
  48. getline(cin, pizzaToppings);
  49. cout << "\n";
  50. if(pizzaToppings.find("onions") != string::npos)
  51. {
  52. totalCosts += 1;
  53. }
  54. else if(pizzaToppings.find("peppers") != string::npos)
  55. {
  56. totalCosts += 1.2;
  57. }
  58. else if(pizzaToppings.find("ham") != string::npos)
  59. {
  60. totalCosts += 1.5;
  61. }
  62. else if(pizzaToppings.find("hamburger") != string::npos)
  63. {
  64. totalCosts += 1.25;
  65. }
  66. else if(pizzaToppings.find("pepperoni") != string::npos)
  67. {
  68. totalCosts += 1.55;
  69. }
  70. else if(pizzaToppings.find("salami") != string::npos)
  71. {
  72. totalCosts += 1.63;
  73. }
  74. else if(pizzaToppings.find("sausage") != string::npos)
  75. {
  76. totalCosts += 1.44;
  77. }
  78. else
  79. {
  80. cout << "Choose at least one valid topping";
  81. return 0;
  82. }
  83.  
  84. // DELIVERY AND FINAL PRINTOUT
  85.  
  86. string needToDeliver = "";
  87. cout << "Do you want delivery? yes/no\n";
  88. getline(cin, needToDeliver);
  89. cout << "\n";
  90. if(needToDeliver == "yes")
  91. {
  92. totalCosts += 3;
  93. cout << "What is your address?";
  94. getline(cin, needToDeliver); // address doesn't matter
  95. }
  96.  
  97. cout << "Your total cost is: $" << totalCosts << ". Thank you for buying C++ Pizza.";
  98. return 0;
  99. }
Success #stdin #stdout 0s 2992KB
stdin
small
stdout
What size is your first pizza?
small:    $8.00
medium:  $10.00
large:   $12.00

Choose from the following toppings:
onions:    $1.00
peppers:   $1.20
ham:       $1.50
hamburger: $1.25
pepperoni: $1.55
salami:    $1.63
sausage:   $1.44

Choose at least one valid topping