Return to site

Dev C Vending Machine Program

broken image
Dev C Vending Machine Program

Vending machine. C / C Forums on Bytes. Give me the code for vending machine in c. It has 10 items in a.first display all the items and its cost and its quantityonhand.then ask the customer if he wishes to buy.if yes tell him to select the item and after that tell him to enter the coins. There should be a 'SHUTDOWN' option with a password for a service person to come and re-stock the machine. Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine.The program should then calculate the amount of change to be returned and subtract one from the number of. Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine.The program should then calculate the amount of change to be returned and subtract one from the number of that drink in the machine.If the user selects a drink which has sold out an appropriate message should be displayed.

We've spent a lot of time over the past few sections talking about how engineers solve problems. In the last section, we saw how this problem-solving approach is applied to the process of software development via project management. At this point, you're probably itching to get your hands dirty with some real code.

In this section, we'll start showing you how to design the solutions to problems without actually knowing how to code by using 'Pseudocode'.

You'll start by learning the basic logical structures of coding and applying them with pseudocode. Then we'll show you how to approach and solve complex development problems by using systems design principles and engineering best practices. Pseudocode is applied here as well, this time to model these systems instead of just individual procedures. By the end of the section, you'll have the engineering know-how to go out and be a truly effective developer.

Dev C Vending Machine Programram

Vending

So What is 'Pseudocode'?

Pseudocode is basically just writing down the logic of your solution to a specific coding challenge using plain English. Or, as Wikipedia puts it:

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.

Programming languages may seem complex, but ultimately, the vast majority of their components are completely interchangeable from one to the next. Whether a language is object-oriented or functional, it will still need to use conditional statements, functions, variables, loops and all manner of other common logical structures. Only the actual syntax for implementing them is different.

Pseudocode is a useful thing to learn because it focuses on the building block concepts of programming languages without you having to worry about whether you are using the 'right' words. Once you've nailed the logic of coding, the rest is just filling in your pseudocode with the syntax of a particular programming language. In a lot of ways, pseudocode is similar to the mockups you created in the Design mini-course: it basically scaffolds the solution you'll be implementing later.

Let's say that I wanted to explain how a vending machine program worked to a general audience. I'd probably write it using pseudocode so you could understand it regardless of whether you are better at Python or Ruby or JavaScript or aren't even a programmer at all:

As you can see, it's a pretty readable logical breakdown of what needs to happen with our vending machine. There's no 'right' way to write these things out; many people skip the indentation and put semicolons at the end of each line, but we'll leave them out to be more Ruby-like. We also could have gone into deeper details or changed up some of the operations a bit, but the core logic has to be there somehow.

Pseudocoding for the Experienced Engineer

Identifying of the core logic of a problem is why working in pseudocode is so useful even after you've been developing for a long time. Most engineers who are trying to figure out a problem will first break out the pen and paper or a dry erase board and pseudocode (aka Whiteboard) the problem because it's easier to see all the moving parts that way and design a good solution. Others will write directly in their text editor and use the pseudocode as actual comments to guide their production of 'real' code.

When approaching a new problem, you will often take an iterative approach: starting by modeling a broad overview of what needs to happen and then filling in each part that requires more detail.

For instance, in the problem above, you might simply start with:

And you can probably see how each one of those gets fleshed out further. As you get more and more detailed, your pseudocode might start resembling real code, with variables and method names naturally coming out of it.

For instance, we might break out a method to check if there is enough money put in:

Vending

Vending machine. C / C Forums on Bytes. Give me the code for vending machine in c. It has 10 items in a.first display all the items and its cost and its quantityonhand.then ask the customer if he wishes to buy.if yes tell him to select the item and after that tell him to enter the coins. There should be a 'SHUTDOWN' option with a password for a service person to come and re-stock the machine. Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine.The program should then calculate the amount of change to be returned and subtract one from the number of. Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine.The program should then calculate the amount of change to be returned and subtract one from the number of that drink in the machine.If the user selects a drink which has sold out an appropriate message should be displayed.

We've spent a lot of time over the past few sections talking about how engineers solve problems. In the last section, we saw how this problem-solving approach is applied to the process of software development via project management. At this point, you're probably itching to get your hands dirty with some real code.

In this section, we'll start showing you how to design the solutions to problems without actually knowing how to code by using 'Pseudocode'.

You'll start by learning the basic logical structures of coding and applying them with pseudocode. Then we'll show you how to approach and solve complex development problems by using systems design principles and engineering best practices. Pseudocode is applied here as well, this time to model these systems instead of just individual procedures. By the end of the section, you'll have the engineering know-how to go out and be a truly effective developer.

Dev C Vending Machine Programram

So What is 'Pseudocode'?

Pseudocode is basically just writing down the logic of your solution to a specific coding challenge using plain English. Or, as Wikipedia puts it:

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.

Programming languages may seem complex, but ultimately, the vast majority of their components are completely interchangeable from one to the next. Whether a language is object-oriented or functional, it will still need to use conditional statements, functions, variables, loops and all manner of other common logical structures. Only the actual syntax for implementing them is different.

Pseudocode is a useful thing to learn because it focuses on the building block concepts of programming languages without you having to worry about whether you are using the 'right' words. Once you've nailed the logic of coding, the rest is just filling in your pseudocode with the syntax of a particular programming language. In a lot of ways, pseudocode is similar to the mockups you created in the Design mini-course: it basically scaffolds the solution you'll be implementing later.

Let's say that I wanted to explain how a vending machine program worked to a general audience. I'd probably write it using pseudocode so you could understand it regardless of whether you are better at Python or Ruby or JavaScript or aren't even a programmer at all:

As you can see, it's a pretty readable logical breakdown of what needs to happen with our vending machine. There's no 'right' way to write these things out; many people skip the indentation and put semicolons at the end of each line, but we'll leave them out to be more Ruby-like. We also could have gone into deeper details or changed up some of the operations a bit, but the core logic has to be there somehow.

Pseudocoding for the Experienced Engineer

Identifying of the core logic of a problem is why working in pseudocode is so useful even after you've been developing for a long time. Most engineers who are trying to figure out a problem will first break out the pen and paper or a dry erase board and pseudocode (aka Whiteboard) the problem because it's easier to see all the moving parts that way and design a good solution. Others will write directly in their text editor and use the pseudocode as actual comments to guide their production of 'real' code.

When approaching a new problem, you will often take an iterative approach: starting by modeling a broad overview of what needs to happen and then filling in each part that requires more detail.

For instance, in the problem above, you might simply start with:

And you can probably see how each one of those gets fleshed out further. As you get more and more detailed, your pseudocode might start resembling real code, with variables and method names naturally coming out of it.

For instance, we might break out a method to check if there is enough money put in:

The above is sort of code and sort of pseudocode. How specific you get with your instructions is up to your preference and the problem at hand.

Check out this example of pseudocoding from Khan Academy.

Wrapping Up

In the next few lessons, we'll cover some of the logical tools you have at your disposal to break apart problems using pseudocode. They are the same logical tools that become real code! We'll lean towards presenting principles used in object-oriented programming languages like Ruby and Python, because that's what you'll be learning later on.

After mastering the concepts of pseudocode and the engineering principles it allows you to apply, you'll be more than ready when we dive into markup and coding in the Advanced Prep.

Yes i know everyone hates homework help but this was a last place i could go I am writing a program that stimulates a vending machine and i have written almost all of the code its just not working correctly I am stressing out because it is due by tomorrow and was wondering if anyone would be able to help me out in any way possible i have attached the *.cpp file and would be willing to do anything if someone would look over it Im not asking for you to completly due it just help me becase i am stuck and do not know were to turn.
In the program it is to give change back which i am having trouble doing so because it breaks it down into half dollars dollars dimes quarters and nickles its really the only problem i have i have written code that i believed to work but it has not if anyone is out there please help
This is what the outcome should look like http://www.cs.ua.edu/114/Summer2004/Programs/prog2.htm

  • 6 Contributors
  • forum11 Replies
  • 2,079 Views
  • 3 Days Discussion Span
  • commentLatest PostLatest Postby Fili

Recommended Answers

Gee, you sure were in a hurry but the lack of full stops really mangles what you say.

This is not really a place to ask for homework answers.But I did look at your code and you use a lot of variables like a,b,c etc for what resonable puprose …

Dev C Vending Machine Programming

Jump to Post

Quite nice,Fili

Jump to Post

I dont think so,it will be of some use to someone,hey teachers usally accept a submission even if it a bit late.

Jump to Post

All 11 Replies

Gee, you sure were in a hurry but the lack of full stops really mangles what you say.

This is not really a place to ask for homework answers.But I did look at your code and you use a lot of variables like a,b,c etc for what resonable puprose I cant guess.Also code is a bit messed up in the sense that it too packed where you calculate the vals so I could not understant it too much either.

But here's something :
Lesson1:Code clearly and use spaces and newlines.They will save your life when it comes to debugging.Noodle code is a death trap.(Your code is not too noodlely except in the if else part).

Lesson 2:Use funtions (I dont know if you know funtions)

Now your prob:One Idea would be to convert the entire amount in to the lowest denomintions availble(nickle?) and calulate using that.In the end convert it back to dollars and show what ever remanins as nickles.Dont bother with quaters unless you have to.
Not much but i could not understand you code nor what was you prob,nor do i have a compiler handy right now. :0





broken image