Thread: C++ Programming Homework, Creating a simple cash register

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    1

    C++ Programming Homework, Creating a simple cash register

    The goal of this program is to create a cash register for the sale of three candies. We are suppose to use call functions to perform a sale, show how many customers there were, total revenue and how many candies were sold. We are not allowed to use any global variables besides the constants that I have declared. I am getting an error that says that every value that I am returning is not initialized, I am not understanding how to fix this error. Hopefully this all makes sense, thanks for the help!
    Code:
    #include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    
    const double  mm = 3.50;
    
    
    const double mandi = 4.0;
    
    
    const double raisn = 2.5;
    
    
    double displayCount(double cmm, double cmandi, double craisn);
    
    
    double makeSale();
    
    
    void displayRevenue(double rev);
    
    
    void displayCustomers(double customers);
    
    
    int menu()
    {
        int choice;
        cout << "Enter 1 to make a sale" << "/n" << "Enter 2 to see number of boxes of each type of candy sold"
            << "\n" << "Enter 3 for total revenue" << "\n" << "Enter 4 to see the number of customers " <<
            "\n" << "Enter 5 to close the program" << endl;
        cin >> choice;
    
    
        while (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5)
        {
            if (choice == 1)
            {
            makeSale();
            }
            else if (choice == 2)
            {
                double cmm, cmandi, craisn;
            displayCount(cmm, cmandi, craisn);
            }
            else if (choice == 3)
            {
             displayRevenue(choice);
            }
            else if (choice == 4)
            {
             double customers;
             displayCustomers(customers);
            }
            else if (choice == 5)
            {
                break;
            }
            else
            {
                cout << "please read the options again and choose one on the list" << endl;
            }
        }
        cout << "please try again" << endl;
    
    
        return choice;
    }
    
    
    double makeSale()
    {
        int a;
        double cmm = 0, cmandi = 0, craisn = 0, customers = 0;
        cout << "Enter 1 for Mike and Ike" << endl << "Enter 2 for Rasiennettes" << endl << "Enter 3 for M & M's " << endl;
        cin >> a;
            double y,rev;
            if (a == 1)
            {
                cout << "What is the quantity? " << endl;
                cin >> y;
                double rev = rev + (y * mandi);
                cmandi = cmandi + y;
                customers++;
    
    
            }
            else if (a == 2)
            {
                cout << "What is the quantity? " << endl;
                cin >> y;
                double rev = rev + (y * raisn);
                craisn = craisn + y;
                customers++;
            }
            else if (a == 3)
            {
                cout << "What is the quantity? " << endl;
                cin >> y;
                double rev = rev + (y * mm);
                cmm = cmm + y;
                customers++;
            }
            else
            {
                cout << "please try again" << endl;
            }
        return rev;
        return cmm;
        return cmandi;
        return craisn;
        return customers;
    }
    
    
    double displayCount(double & cmm, double & cmandi, double & craisn)
    {
            cout << "You sold " << cmm << " M&Ms and " << cmandi << " Mike and Ikes and " << craisn << " Raisennettes" << endl;
        return 0;
    }
    
    
    void displayRevenue(double & rev)
    {
            cout << "The total revenue for the day is " << rev << endl;
    }
    
    
    
    
    void displayCustomers(double customers) 
    {
            cout << " The number of customers is: " << customers << endl;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Functions can only return a single value in C and C++.

    The typical way to work around this issue using pointers or returning an structure.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Or use references, like you do here.
    > double displayCount(double & cmm, double & cmandi, double & craisn)

    > The goal of this program is to create a cash register for the sale of three candies.
    Your first goal should have been to create a cash register for the sale of ONE candy.

    You have to learn how to break the problem down into smaller steps, which you can test along the way.
    If you were stuck at the 1 candy problem, there's no point compounding the error by adding extra candies. You just end up with a deeper hole, not a solution.

    A development process
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic C Help - Cash Register
    By Bernard Wu in forum C Programming
    Replies: 3
    Last Post: 02-06-2013, 11:12 AM
  2. C++ Cash Register Help
    By nealw in forum C++ Programming
    Replies: 5
    Last Post: 10-11-2011, 08:46 PM
  3. help me fix one problem with my cash register
    By lil_rom in forum C Programming
    Replies: 3
    Last Post: 04-14-2008, 12:03 AM
  4. Cash register program help :(
    By lil_rom in forum C Programming
    Replies: 2
    Last Post: 04-11-2008, 12:35 AM
  5. Cash Register
    By Hursh in forum C Programming
    Replies: 5
    Last Post: 01-22-2002, 03:36 AM

Tags for this Thread