Functions

Im supposed to design a program that simulates a vending machine that sells icecream.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
const double maxCones = 10;
const double maxScoops = 5;
double cones, scoops, priceScoop, bill;
cout << "Welcome To Daniels IceCream! \n" ;
cout << "\n" ;
cout << "Here is the Menu:\n" ;
cout << "Flavor @ \n" ;
cout << "Flavor # \n" ;
cout << "Flavor $ \n" ;
cout << "\n" ;
cout << "Scoop Pricing: \n" ;
cout << "1 scoop ----> $1.00\n" ;
cout << "2 scoop ----> $2.00\n" ;
cout << "Every scoop after is $1.00 extra.\n" ;
cout << "\n" ;
cout << "There is also a maximum of 10 cones and 5 scoops per cone!\n" ;
cout << "\n" ;
cout << "First Enter the ammount of cones you would like. \n" ;
cin >> cones;
while (cones <=10)
{
cout << "Coming right Up!\n";
break;
}
cout << endl;
cout << "Okay now how many scoops would you like? \n";
cin >> scoops;
while (scoops <=5)
{
cout << "I dont think you can handle that many!\n";
break;
}
cout << endl;

Im confused as to how am supposed include the total bill for the customer. I could simply just change the price of the scoops to be one dollar and then just do bill = cones*scoops but i wouldn't learn anything from that.
Just keep a running total amount which you add to after every order.
so, if the user inputs 3 for scoops

the price would be ($2.00 + $1.00)*(number of cones)

but if the user inputs 4 scoops
(it would be (2.00+1.00+1.00)*(number of cones)

but instead of doing the price for 1 scoop, 2 scoops, 3 scoops, 4 scoops , 5 scoops by making a separate constant for each number of scoops is there a certain function I'm missing to make it simpler?
closed account (zwA4jE8b)
Do you need to keep a running total? You could use a static if you want, but your program doesn't loop, from what I can see. Basically all you can do with the two numbers is multiply them, yeah you could pass that to a function but that seems unnecessary in this case.

if the first scoop cost 2 and the extra cost 1 then (2+n)*cones
Last edited on
I dont understand how to fully loop yet as well as error checking aspects.

The (2+n)*cones makes sense for the anything with 2 scoops and up. but if the user inputs 1 scoop i would have to make a new function dedicated for that 1 scoop right?
closed account (zwA4jE8b)
no because n is zero, 2+0 = 2

(2+n)*cones is done no matter what. so if 1 scoop is entered n=0 so n=scoops -1;
Last edited on
Thanks! so i would probably be using the for statement.
Topic archived. No new replies allowed.