I know a lot of students get on here and post threds trying to get others to do their homework, but i truly need help! I am looking for someone who is willing to tutor me by Im, e-mail, phone or anything. I have a coke machine project due next week and I want to do the work myself but I have no clue and the professor thinks I should know how to do it by now. Please Help!!!!!!!!!!:sad:

Recommended Answers

All 22 Replies

the professor thinks I should know how to do it by now.

You prolly do, but sometimes solutions aren't obvious, especially when you're new to problem solving. Your professor is there to teach you and give advice, so he's not off the hook with that excuse. :)

I have a coke machine project due next week and I want to do the work myself but I have no clue

Can you post the requirements? I'll be happy to help you understand what needs to be done, then you can fill in the blanks.

Does your coke machine do anything more than
- take money
- give can of coke
- give change
?

Take your assignment and put it in your favourite word processor, and reformat it so there is plenty of white space after each sentence with words like "shall", "must", "should" (all the things you need to do basically).

Print that off and start making notes in the gaps about what you understand about the statement. Start categorising things into "input", "process" and "output" say.

Or maybe think about an OO model, say "cans", "money", "keypad" and "display".

Once you've got some idea of the whole picture, you can implement and test it in bits.

These are the requirements for the project:
It
In this machine, you will need to handle all appropriate operations performed by such machines. Namely, you have a finite supply of drinks; you accept quarters, dime, nickels, and dollar bills. Money is entered AND dispensed in appropriate denominations.

Givens: Our machine contains the following drinks in the following quantities
Coke – 4
Sprite – 2
Diet Coke – 1
Mr. Pib – 3
Water – 2

All drinks are 55 cents.

Your professor is there to teach you and give advice, so he's not off the hook with that excuse. :)
quote]

I wasnt trying to say that he is not a good professor, in fact he knows a lot about what he is doing. Is just that he is SO advanced he thinks everyone in the class should be understanding faster, and that is not the case for me. Im even confused on what questions to ask when im confused........I guess programming just isnt my thing!:sad:

I wasnt trying to say that he is not a good professor, in fact he knows a lot about what he is doing. Is just that he is SO advanced he thinks everyone in the class should be understanding faster

Then he might not be as good a teacher as you think. A good teacher needs to know the topic, but also be able to understand the difficulties of the people he's teaching. It's kind of a catch-22 because if you get to the point where you really know the topic, you've probably outgrown the point where you can think like a beginner. But that's not an excuse either. ;)

In this machine, you will need to handle all appropriate operations performed by such machines. Namely, you have a finite supply of drinks; you accept quarters, dime, nickels, and dollar bills. Money is entered AND dispensed in appropriate denominations.

Givens: Our machine contains the following drinks in the following quantities
Coke – 4
Sprite – 2
Diet Coke – 1
Mr. Pib – 3
Water – 2

All drinks are 55 cents.

Okay, on the surface it's overwhelming. Believe me, I know. :) But if you break it up into bite-size pieces, life is much easier. Let's see, we can start by getting a feel for the "hardware".

You can prolly get away with taking a literal translation and just using integers like 'coke' and 'sprite' that count down to 0. Personally, I'd generalize it so that the "machine" has five slots with a set capacity so that you can refill it with different types of pop. So let's make a storage category for your tasks. The storage category should handle a few jobs.

  • Keep track of how many bottles are stored
  • Release one bottle when signaled by the controller
  • Talk to the controller

Pretty simple, that one, and you can add bells and whistles later if you want. Next is the changer. The changer handles the taking and returning of money, which happens to be a common beginner's assignment. :) By "appropriate denominations", the requirements are asking you to give back decreasing amounts. So $0.55 out of a dollar would return one quarter and two dimes rather than four dimes and a nickel. Like the storage part, the changer has a few basic jobs.

  • Count money coming in
  • Return change for a purchase
  • Return the same amount received for a no-sale
  • Talk to the controller

The changer also needs to be able to tell the controller if enough money has been inserted for a bottle to be released. The controller is the brain that links the changer and the storage pieces together. It's the controller that knows which slot a coke is in and which slot a sprite is in. The controller's jobs are more numerous.

  • Keep track of what pop type is in what slot
  • The cost for an item in each slot
  • Determining if enough money has been entered
  • Interfacing with the user
  • Determining how much change is required
  • Notifying the user of an empty slot
  • Telling a slot to release one bottle

Now I'll hand the torch to you and let you see if you can break it down further and maybe come up with a demo. :)

I guess programming just isnt my thing!

Everyone thinks that sooner or later. Programming is a skill, and everyone learns differently. Just because you might not be as fast as someone else doesn't mean you won't end up the better programmer. :)

I know a little about what you wrote, but my whole thing is what code to type in. I dont understand that <#include> and iostream stuff. For example:

he gave us some help on how to code the changer. I dont know when to put if(), else().......i dont know if im explaining it right, but this stuff just doesnt make sense to me at all! I flowcharted the Coke machine but he told me it was too general.

How far into this class are you?

We are on a block schedule and this is the second week. we go to class for 21 days. he said that this is the last coding project we will do. We programmed blackjack last week....i got the coding for the user, but couldnt get it right for the dealer. I really need help, we dont have a tutor for this class.

I was complicating things for you, sorry. I thought you were further along. Okay, looking at it differently, this sounds like a simple program except for the two crux areas which would be the changer and the user interface. The storage I was talking about really would be a few integers with preset values.

The problem is that I'm not really a good teacher, so I can't give you a good starting point without writing code for you. :(

No problem, whatever you can do to help is fine with me! I dont want to fail this class. It is due Tuesday. A lot of people are having problems with it also.

kk, menus are pretty standard and simple. If you've done one you've done 'em all. Here's a quick one that'll work for your program, but you still need to glue it with the rest of your code. :)

// Simple menu example
//
#include <iostream> // Gives you cin and cout

int main()
{
    // So you don't have to prefix cin and cout with std::
    using std::cin;
    using std::cout;

    bool done = false; // Know when to stop looping
    int selection; // Menu option from Mr. User

    while (!done) {
        // Print the menu
        cout<<"1) First thing\n2) Second thing\n";
        cout<<"3) Third thing\n4) Quit\n";
        cout<<"Selection: ";

        while (true) {
            // Make sure Mr. User typed a good selection
            if (cin>>selection && selection > 0 && selection < 5 )
                break;

            // Something bad happened, tidy up and try again
            cout<<"Selection error. Please try again: ";
            cin.clear(); // Clear the error state
            cin.ignore(256, '\n'); // Remove unwanted stuff
        }

        // Do something different for each selection
        switch (selection) {
        case 1:
            cout<<"You chose the first thing!\n";
            break;
        case 2:
            cout<<"You chose the second thing!\n";
            break;
        case 3:
            cout<<"You chose the third thing!\n";
            break;
        case 4:
            done = true;
            break;
        }
    }

    cout<<"Thanks for playing!\n";
}

Remember how I broke things down before when I was being complicated? That still applies 'cause you can get things like the menu and the changer working by writing separate simple programs, then the only problem is integration.

Thank you sooooo much!!!! You just dont know how much help just that has done for me! So those //'s mean that it wont show up on the screen when I run it, right? I will repost the code when Im done so you can possibly help me check for errors.

THANK YOU!!!!!

So those //'s mean that it wont show up on the screen when I run it, right?

They're comments. They're important info for you, my friend. :) The compiler just ignores them. It's a good thing too, 'cause my ramblings don't even come close to C++ syntax. :D

commented: great posts that were very helpful +1

Im working on it right now, and I am trying to go step by step. I put in a little bit of the information for the requirements. I am supposed to compile it first, then run it. But after I created a directory I need to create a file. but everytime I go to compile it, it gives me this error message:

g++: shank.cpp: No such file or directory
g++: no input files

shank.cpp is my directory.
filename is cokemachine

OK...I got that part fixed. I had to remember some things from my notes. I compiled it and ran it and it returned 4 errors sayin:

cokemachine.cpp:34: error: case label `1' not within a switch statement
cokemachine.cpp:37: error: case label `2' not within a switch statement
cokemachine.cpp:40: error: case label `3' not within a switch statement
cokemachine.cpp:43: error: case label `4' not within a switch statement

Can you paste the code that you're using?

Can you paste the code that you're using?

Sure..

// Simple menu example
//
#include <iostream> // Gives you cin and cout
int main()
{
    // So you don't have to prefix cin and cout with std::
    using std::cin;
    using std::cout;
    bool done = false; // Know when to stop looping
    int selection; // Menu option from Mr. User
    while (!done) {
        // Print the menu
        cout<<"1) Coke\n2) Diet Coke\n";
        cout<<"3) Sprite\n4) Mr Pibb\n";
        cout<<"5) Water);
        cout<<"Selection: ";
        while (true) {
            // Make sure Mr. User typed a good selection
            if (cin>>selection && selection > 0 && selection < 5 )
                break;
            // Something bad happened, tidy up and try again
            cout<<"Selection error. Please try again: ";
            cin.clear(); // Clear the error state
            cin.ignore(256, '\n'); // Remove unwanted stuff
        }
        // Do something different for each selection switch (selection)
 {
        case 1:
            cout<<"Coke\n";
            break;
        case 2:
            cout<<"Diet Coke\n";
            break;
        case 3:
            cout<<"Sprite\n";
            break;
        case 4:
            cout<<"Mr Pibb\n";
            break;
        case 4:
            cout<<"Water\n";
            done = true;
}
    }
    cout<<"Thank You\n";
}

I'd like to say it's what I thought it was. :D

// Do something different for each selection switch (selection)

Remember how the compiler ignores comments? Well, the // comment goes to the end of the line. You need a line break of the switch will be thrown into limbo.

// Do something different for each selection
switch (selection)

You are a freakin GENIUS!!!! OK I got that now I have to insert my code for the change dispenser. Should I place that before the soda selection stuff, or does it not matter. Heres the code I have:

Change = Total – Cost;
 If (Change = = 45)
 { cout<<”Your change is 1 quarter and 2 dimes”;
 }
 Else if (Change = = 20)
 { cout<<”Your change is 2 dimes”;
 }
 Else if (Change = = 5)
 { cout<<”Your change is 1 nickel”;
 }
 Else if (Change = = 0)
 ( cout<<”Do you want another drink?”;

Where is the variable which keeps tab of the total amount present with the user? You keep on using the variable "total" but i dont see it declared anywhere.

You can check after your switch stmt whether the user has the required amount of money to buy that drink. And if he hasnt got then you can jsut duck out of hte program. IF he has the required amount allow the user to select the drink of his choice and then post the remaining code you have written after the selection.

Keywords in C are case sensitive, you just cant get away by using it your own way.
Replace If with if Else with else .

If you want to compare two things using the == no spaces are allowed between the two equals.

I am still having a problem with my code. I need it to show inventory of the cans of soda, ask for money before it asks for the soda selection. Here is the code I have already. I need suggestions on how to get it to where it needs to be.

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
 
{
int Total = 0;
int Cost = 55;
int Cokeleft =4 ;
int DCokeleft =1;
int Spriteleft =2;
int Pibbleft =3;
int Waterleft = 1;
int Change;
int money;
int done;
int Return = 0;
int selection;
 
{
 
bool done = false; // Know when to stop looping
int selection; // Menu option from Mr. User
int selection1; 
}
 
while (Total < 55 && Return <1)
if(money !=1 && Return <1)
{
//Ask for money
cout<<"Please Insert 55 cents"<<endl;
}
{
switch (selection1);
case 1:
cout<<"Insert a Quarter"<<endl;
break;
case 2:
cout<<"Insert a Dime"<<endl;
break;case 3:
cout<<"Insert a Nickel"<<endl'
break;
}
while (!done) {
// Print the menu
cout<<"1) Coke"<<endl;
cout<<"2) Diet Coke"<<endl;
cout<<"3) Sprite"<<endl;
cout<<"4) Mr Pibb"<<endl;
cout<<"5) Water"<<endl;
cout<<"Selection: ";
while (true) {
// Make sure user typed a good selection
if (cin>>selection && selection > 0 && selection < 6 )
break;// Something messed up, try again
cout<<"Selection error. Please try again: ";
cin.clear(); // Clear the error state
cin.ignore(256, '\n'); // Remove unwanted stuff
}
// Put different soda for each selection
switch (selection)
{
case 1:
cout<<"Coke"<<endl;
done = true;
break;
case 2:
cout<<"Diet Coke"<<endl;
done = true;
break;
case 3:
cout<<"Sprite"<<endl;
done = true;
break;
case 4:
cout<<"Mr Pibb"<<endl;
done = true;
break;
case 5:
cout<<"Water"<<endl;
done = true;
break;
done = true;
}
}
cout<<"Thank You!"<<endl;
Change = Total - Cost;
if(Change == 45)
{
cout<<"Your change is One quarter and Two dimes"<<endl;}
else if(Change == 20)
{
cout<<"Your change is Two dimes"<<endl;
}
else if(Change == 5)
{
cout<<"Your change is One nickel"<<endl;
}
else if(Change == 0)
{
cout<<"Do you want another drink?"<<endl;
}
return 0;
}

Think about adding some functions to make your main() a lot less busy.

Say along the lines of

int main ( ) {
  while ( true ) {
    displayInventory();
    displayOption();
    getChoice();
    dispenseDrink();
    giveChange();
  }
  return 0;
}

Add suitable parameters to each function.

Consider a structure containing the following
- the name of the drink
- the price of the drink
- the number of cans available

Be a part of the DaniWeb community

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