|
Hi,
i have this assignment and i would like some help with it please. It is my first assignment ever in c++ and it is my first go at writing code for it. Ill post the question and my code so far if anyone could help me get the code correct and working would be really great.
Question:
Your program should operate continuously with a list of drinks and their costs displayed on screen. there should also 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 the drink in the machine. If the user selects a drink which has sold out an appropriate message should be displayed. Some input validation should be carried out on the amount eg. no negative values and no amount larger than $10.
When the "Shutdown" option is chosen the system should report total turnover and number of each drink left in the machine. After a suitable input from the service person the system should then reset the number of drinks back to the initial values and resume normal operation.
Arrays must be used and an expected looping menu-structure.
the drinks are:
coca cola...$1.50....30 (in machine)
sprite........$1.60....30
fanta.........$1.70....30
ginger beer...$1.90.....30
powerade.....$3.50.....20
And this is what i have done so far. It's all mixed up but please forgive me as its my first go. Please help me if you can?
//
//
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const int SIZE = 5; // Array size.
struct drink_machine
{
string drinkName ;
double drinkCost;
int numDrink;
double buyDrink;
float moneyIn;
float moneyOut;
int drinks ;
int inputMoney;
double choice;
};
struct drink_machine drink_mach[SIZE];
int main()
{
int menuChoice=1, choice;
drink_mach[0]= "Coca Cola";
drink_mach[1]= "Sprite";
drink_mach[2]= "Fanta";
drink_mach[3]= "Ginger Beer";
drink_mach[4]= "Powerade";
while(menuChoice != 6)
{
cout << "Choose A Drink To Purchase: " << endl;
cout << "1 - Coca Cola" << endl;
cout << "2 - Sprite" << endl;
cout << "3 - Fanta" << endl;
cout << "4 - Ginger Beer" << endl;
cout << "5 - Powerade" << endl;
cout << "6 - Quit\n" << endl;
choice = menuChoice;
}
return 0;
}
|
|
|
|
|
queenzz wrote: Please help me if you can?
There is so much still to do here that it is almost impossible to 'help' without doing all your work for you. I would suggest writing out the steps the program needs (in natural language) and then trying to convert what you have written into actual code. You also need to spend some time studying the use of struct s and class es to use as your drinks. For example your individual drinks probably need to be held in a 'drink' class and will need a number to show price and availability.
|
|
|
|
|
queenzz wrote: i have this assignment...
From Tony Gaddis' book?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Inside a message handler for WM_LBUTTONDOWN , several functions are being called, one of which is known to display a dialog box under certain circumstances. Prior to this function being called, the mouse is captured using SetCapture() . However when that dialog is shown, the WM_LBUTTONUP appears to be getting swallowed by that dialog, and as such, to the underlying control that spawned the dialog, the mouse still appears to be down.
In looking for a passive method of detecting whether the dialog has been displayed, the code will call GetCapture() to retrieve the handle to the current window with the capture and check it against the handle to which the capture had been previously set. If the handles are different, it will post a WM_LBUTTONUP message to the message queue to "complete the click". Sample code:
::SetCapture(hWnd);
FunctionThatCouldDisplayADialog();
HWND hWndCapture = ::GetCapture();
if(hWnd != hWndCapture)
{
::PostMessage(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
}
With some testing of various scenarios (with more to come), this appears to be a reliable method to determine if a dialog was displayed during the current line of execution. To quote the manager of my team, this wreaks of being a hack, and as such, we're still mildly skeptical on the reliability of this method. I'm looking for feedback on this and whether anyone can see any potential pitfalls, issues or concerns for which we should be accounting.
Thanks.
|
|
|
|
|
Can you check if you can use WM_ACTIVATE message on your main window?. The state is supposed to be WA_INACTIVE when the dialog box is displayed.
|
|
|
|
|
Unfortunately given the way the solution is overall designed, that is not possible.
|
|
|
|
|
When I compiled a free-source code for a KLT point implementation (a feature point used widely in Computer vision) using VC with MFC support,
I got a compilation error "error C2632: 'float' followed by 'char' is illegal " for the line:
"float small,"
and error "C2062: type 'char' unexpected" for the line " if (det < small) return (int)(KLT_SMALL_DET);"
Seems the variable name "small" is illegal in VC 2005, I have tried "t_small" instead, then the problem is gone!!
That is really weird!!! Is "small" a reserved keyword in VC2005?.
I have never seen that kind of error message before!.
Following is the source code, the problematic line is in bold font:
static int _solveEquation(
float gxx, float gxy, float gyy,
float ex, float ey,
float small,
float *dx, float *dy)
{ float det = gxx*gyy - gxy*gxy;
if (det < small) return (int)(KLT_SMALL_DET);
*dx = (gyy*ex - gxy*ey)/det;
*dy = (gxx*ey - gxy*ex)/det;
return KLT_TRACKED;
}
|
|
|
|
|
According to this[^] it shouldn't.
Is there any typedef or any other kind of association with that word in the programm? Try to look for "small" in all files in your project. The compiler can complain about that use, but the cause could be in any other place.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
The source code you provided compiles fine on 2010 (provided KLT_SMALL_DET and KLT_TRACKED are defined).
Are you sure there arent't spurious characters in your original source file?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You missed one of the bold-lines, the problem is not with KLT_SMALL_DET, it is with "small" variable name.
And the fact that you can compile that code snippet, is a kind of confirmation about my theory that "small" is maybe being defined in other place.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I missed nothing, of course.
I copied the whole OP function and made it compilable by defining (with dummy values) KLT_SMALL_DET , KLT_TRACKED just to check if small could be the issue: it turned out that was not the case.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I think I have to readapt the "if you drink, don't drive" with "if you drink, don't post in CP", it is my second missunderstanding today
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nah, I post here only while I'm very well drunk...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Aaah, ok, now I understand
|
|
|
|
|
Cedric Moonen wrote: Aaah, ok, now I understand
Noooooooooooo, you cannot understand: you're just freshly married...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
siyuanfang wrote: I got a compilation error "error C2632: 'float' followed by 'char' is illegal " for the line:
"float small,
If you hover your mouse over the word small it shows #define small char , and Go To Definition takes you to line 153 in RpcNdr.h .
|
|
|
|
|
I've the variable
float hops; causing a similar problem.
Could you please indicate the header file and the line number of the troubling #define ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: float hops;
Sorry, doesn't show up in my compilation unit. If you get the problem why can't you find its definition using the method above? Or are you not using Visual Studio?
[edit]But I suspect 'hops' has something to do with TCP/IP[/edit]
|
|
|
|
|
Richard MacCutchan wrote: Or are you not using Visual Studio?
Yes, I'm using Visual Beck's .
Richard MacCutchan wrote: [edit]But I suspect 'hops' has something to do with TCP/IP[/edit]
Actually I suspect it is related to Lager/Brewing ...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Aaargh! you got me ... 
|
|
|
|
|
I know this may look a little more than a little strange! But for a reason I want to write a whole function in a file at run-time. OK, let's do some clarification:
see you have a function like:
void foo ()
{
your code ...
}
after compilation we have some thing like:
push 210
mov eax, ebx
...
and in binary level:
E8 00 DA 65 00 00 DF
What I need is to write these binary codes in a file.
Note
1- There's no such an instruction like mov eax, eip or pop eip in Intel instruction set. Actually there's no instruction to get or set eip directlt.
Thank you masters!
|
|
|
|
|
Why don't you get the compiler output?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
because I need to write it anywhere I want. I don't want to use the simple copy-paste method.
|
|
|
|
|
The you have to write a compiler...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
As I understand it, you want to include in your executable, a number of Datablocks which you want to use as prototype executable files, to be called by your process. This can be done, and I've done it. If that's what you want, it also requires No ASM Code to implement!
Bram van Kampen
|
|
|
|