I am a newbie so please forgive my ignorance. I need help with this program, it is outputting 1s for the functions. I know it's something simple, but like I said I am new and don't know what to do.

#include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

const double M = 4.99;
const double L = 7.99;
const double TOPPINGS = .85;
const double DISCOUNT = .90;
const double DELIVER_RATE = .12;
const double ZERO = 0.00;

//functions used
double perPizza(char sizeOfPizza, int numberOfToppings);
double councilDiscount(string studentDiscount, double numberOfPizzas);
double pizzaSubtotal(double amountStudentDiscount, double totalPriceOfPizza);
double billTotal(double amountOfDelivery, double subtotalOfPizza);
double deliveryCharges(bool deliver, double subtotalOfPizza);
double pizzaTotal(double pricePerPizza, double numberOfPizzas);

int main ()
char sizeOfPizza;
double numberOfPizzas;
double numberOfToppings;
string studentDiscount;
bool deliver;
double pricePerPizza;
double amountStudentDiscount;
double totalPriceOfPizza;
double subtotalOfPizza;
double amountOfDelivery;
double totalOfBill;

cout << "Pizza Bill Calculation Program" << endl << endl;
cout << "Size of Pizza, medium or large (M/L): ";
cin >> sizeOfPizza;     //get size of pizza from user

cout << "Enter the number of pizzas ordered: ";
cin >> numberOfPizzas;      //get number of pizzas from user

cout << "Enter the number of toppings: ";
cin >> numberOfToppings;        //get number of toppings from user

cout << "Student Council Member (yes or no - all lowercase): ";
cin >> studentDiscount;     //get student council member, yes or no

cout << "Pickup or Delivery (P or D): ";
cin >> deliver;     //get choice of delivery or pickup
cout << endl;

cout << "Order Details" << endl << endl;

cout << "Size of Pizzas: ";
cout << setw(27) << fixed << right << setprecision(2);
sizeOfPizza = toupper(sizeOfPizza);

cout << "Medium" << endl;

cout << "Large" << endl;

cout << "Number of Toppings: ";
cout << setw(23) << fixed << right << setprecision(0) << numberOfToppings << endl;

cout << "Price per Pizza: ";
cout << setw(26) << fixed << right << setprecision(2) << perPizza << endl;

cout << "Number of Pizzas Ordered: ";
cout << setw(17) << fixed << right << setprecision(0) << numberOfPizzas << endl << endl;

cout << "PIZZA BILL" << endl << endl;

cout << "Pizza Total: ";
cout << setw(30) << fixed << setprecision(2) << pizzaTotal << endl;

cout << "Student Council Discount: ";
cout << setw(17) << fixed << setprecision(2) << councilDiscount << endl;

cout << "Subtotal of Pizza Order: ";
cout << setw(18) << fixed << setprecision(2) << pizzaSubtotal << endl;

cout << "Delivery Charges: ";
cout << setw(25) << fixed << setprecision(2) << deliveryCharges << endl;

cout << "Bill Total: ";
cout << setw(31) << fixed << setprecision(2) << billTotal << endl;

return 0;

double perPizza(char sizeOfPizza, int numberOfToppings)
     double pricePerPizza;

        pricePerPizza = TOPPINGS * numberOfToppings + M;

        pricePerPizza = TOPPINGS * numberOfToppings + L;
        return pricePerPizza;

double councilDiscount(string studentDiscount, double numberOfPizzas)
     double amountStudentDiscount;

        amountStudentDiscount = numberOfPizzas * DISCOUNT;

        amountStudentDiscount = ZERO;

    return amountStudentDiscount;

double pizzaTotal(double pricePerPizza, double numberOfPizzas)
    double totalPriceOfPizza;

    totalPriceOfPizza = pricePerPizza * numberOfPizzas;
    cout << endl;
    return totalPriceOfPizza;

double pizzaSubtotal(double amountStudentDiscount, double totalPriceOfPizza)
    double subtotalOfPizza;

    subtotalOfPizza = totalPriceOfPizza - amountStudentDiscount;
    cout << endl;
    return subtotalOfPizza;

double deliveryCharges(bool deliver, double subtotalOfPizza)
    double amountOfDelivery;

    if(deliver == 'D' || 'd')
        amountOfDelivery = subtotalOfPizza * DELIVER_RATE;

    return amountOfDelivery;

double billTotal(double amountOfDelivery, double subtotalOfPizza)
    double totalOfBill;

    totalOfBill = amountOfDelivery + subtotalOfPizza;
    cout << endl;
    return totalOfBill;
    system ("PAUSE");

Recommended Answers

All 7 Replies

Could you narrow down your problem to something smaller than the entire program?

P.S. Please use an appropriate title for your posting. Need Help ASAP isn't very descriptive.

The problem is the functions not outputting anything but a one. I just needed someone to tell me what mistake I am making with the functions that would cause this. I am not sure how I can go about narrowing it down. Thanks!

Which line is the function called on?

your not passing any actual paramater on the functions
also local variables found in the functions will only be visible to the calling function (main) if you save their values

I see 6 functions. Based on both your threads, it's time to dust off the:

Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, they are a cheater.
    -If you use that code you are a cheater.
  7. Do not bore us with how new you are. We can tell by your code.
    -Do not apologize. We were all new, and unless you are completely brain dead you will get better.
    -Do not ask us to "take it easy on you."
    -Do not say "I don't know what's going on." That's obvious since you posted for help. Use that time wisely by explaining as best you can so we can help.
  8. Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
  9. Do not post your requirements and nothing else. We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we will be hard on you.
  10. Do not attach files except when absolutely necessary. Most of us are not going to download files. Add the information to your post.
  11. Do not tell us how urgent it is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
  12. Create a good title for your post. The title C++ in the C++ forum is bloody redundant and worthless! What's wrong? equally so. Specifically what are you having trouble with? There is your title. (note: my program is not the answer.)

Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

When you are writing a function prototype, you dont have to supply argument names, just type of argument shall work fine.

double perPizza(char sizeOfPizza, int numberOfToppings);

replace by

double perPizza(char , int );

Also line 78 and 86, you have written << perPizza and << pizzaTotal. By seeing your prototypes, they are functions. Are you allowed to do that ?

Line 178 : Avoid system(); calls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.