Created
March 21, 2018 02:39
-
-
Save LOZORD/a23a39d67d94f88361679b5c6284d812 to your computer and use it in GitHub Desktop.
My first C++ program (started 3/1/13)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// test!!! | |
// | |
// Created by Leo Rudberg on 3/1/13. | |
// Copyright (c) 2013 Leo Rudberg. All rights reserved. | |
// | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
int main(int argc, const char * argv[]) | |
{ | |
//HERES A COMMENT! | |
// insert code here... | |
// std::cout << "THIS WORKS!!\n"; | |
// int x = 500; | |
// std::cout<<x; | |
char mainChoice; | |
char fryChoice; | |
bool fries = false; | |
float total = 0; | |
const double bratPrice = 2.5; | |
const double hambPrice = 3.0; | |
const float fryPrice = 1.5; | |
const float smallPrice = 1.25; | |
const float medPrice = 1.50; | |
const float largePrice = 1.75; | |
const float tax = 0.15; | |
string drinks [] = {"Water","Coke","Diet Coke","Sprite","Root Beer", | |
"Ginger Ale","Orange Soda","Cream Soda"}; | |
string ourDrinks = ""; | |
std::stringstream ss; | |
string myOutput; | |
const int MAX_CAPACITY = 55; | |
ss << MAX_CAPACITY; | |
myOutput = ss.str(); | |
for (int i = 0; i < 7; i++) | |
{ | |
ourDrinks += "-" + drinks[i] + "\n"; | |
} | |
ourDrinks += "-" + drinks[7]; | |
cout<<"Welcome to Leo's C++ Diner!\n"; | |
//XXX string concatenation | |
string menu = | |
string("MAIN DISHES:\n-BRATS $2.50 \n-HAMBURGERS $3.00") | |
+ string("\nSIDES:\n-FRIES $1.50 \nDRINKS: \n") | |
+ string(ourDrinks) + | |
string( "\nDRINK PRICES: \nSmall $1.25 \nMedium $1.50") + | |
string("\nLarge $1.75\nWater only comes in Small for $1.00\nTax is 15%.\n") | |
+ "Our maximum number of occupants is " + myOutput + ".\n"; | |
cout<<menu; | |
std::cout<<"\nEnter in Brat or Hamburger. (B,H)\n"; | |
std::cin>>mainChoice; | |
std::cout<<"How many would you like?\n"; | |
int amnt = 0; | |
std::cin>>amnt; | |
std::cout << "Would you like fries? (Y,N)\n"; | |
std::cin >> fryChoice; | |
std::string mainFood = ""; | |
if (fryChoice == 'y' || fryChoice == 'Y') | |
{ | |
fries = true; | |
} | |
if (mainChoice == 'b' || mainChoice == 'B') | |
{ | |
if (fries) | |
{ | |
total +=fryPrice; | |
} | |
total += (amnt * bratPrice); | |
mainFood = "BRAT(S)"; | |
} | |
if (mainChoice == 'h' || mainChoice == 'H') | |
{ | |
if (fries) | |
{ | |
total +=fryPrice; | |
} | |
total += (amnt * hambPrice); | |
mainFood = "HAMBURGER(S)"; | |
} | |
std::cout<<"What do you want to drink?\nEnter a number 1 thru 8.\n"; | |
int drinkChoice = 0; | |
cin>>drinkChoice; | |
//has next int available? | |
while (drinkChoice <= 0 || drinkChoice > 8) | |
{ | |
cout<<"Please enter in a number 1 thru 8!"; | |
cin>>drinkChoice; | |
} | |
drinkChoice--; | |
char drinkSize; | |
string myDrink = drinks[drinkChoice]; | |
string printDrink = ""; | |
bool gotToy = false; | |
if (myDrink == "Water") | |
{ | |
cout<<"Water is $1.00 in SMALL only.\n"; | |
total += 1.00; | |
printDrink = "You ordered a SMALL Water.\n"; | |
} | |
else | |
{ | |
cout<<"What size do you want? (S,M,L)\n"; | |
cin>>drinkSize; | |
if (drinkSize == 's' || drinkSize == 'S') | |
{ | |
total += smallPrice; | |
printDrink = "You ordered a SMALL " + myDrink + ".\n"; | |
} | |
else if (drinkSize == 'm' || drinkSize == 'M') | |
{ | |
total += medPrice; | |
printDrink = "You ordered a MEDIUM " + myDrink + ".\n"; | |
} | |
else if (drinkSize == 'l' || drinkSize == 'L') | |
{ | |
total += largePrice; | |
printDrink = "You ordered a LARGE " + myDrink + ".\n"; | |
if (myDrink == "Ginger Ale") | |
{ | |
gotToy = true; | |
} | |
} | |
} | |
std::cout<< "Your total is : $" ; | |
std::cout.setf(std::ios::fixed); | |
std::cout.setf(std::ios::showpoint); | |
std::cout.precision(2); | |
//std | |
std::cout <<total; | |
std::cout <<"\n"; | |
std::cout <<"Because you ordered " << amnt<< " " << mainFood<< "."; | |
if (fries) | |
{ | |
std::cout<< "\nYou also ordered fries."; | |
} | |
std::cout <<"\n"; | |
cout<<printDrink; | |
cout<<"Your final payment is : $"; | |
cout<<total + (total * tax); | |
std::cout<<"\nThanks and enjoy your meal!\n"; | |
if (gotToy) | |
{ | |
string secretToy = | |
string( "I forgot to mention that with the purchase of a large") | |
+ | |
string | |
(" Ginger Ale, you receive a toy.\nI will pick the toy randomly, but I") | |
+ | |
string( " need a seed number first!\n"); | |
cout<<secretToy; | |
int seed; | |
cin>>seed; | |
string toys [] = {"Paddleball","Action Figure","Fortune Cookie", | |
"Decoder Ring", "Whistle", "Crayons"}; | |
srand(seed); | |
int toyChoice = rand() % 6; | |
cout<<"Congrats! You received a: " + toys[toyChoice] + "."; | |
} | |
/* | |
This is the end of the class! | |
*/ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment