|
 Malli,
Thank you for your input. I found a number of corrections on other boards. As a result here is the corrected version:
#include <stdio.h>
#include <conio.h>
#define Artichoke 1.25
#define Beets .65
#define Carrots .89
#define Discount .05
#define Shipping1 10.00
#define Shipping2 8.00
int main(void)
{
char ordercom;
char type;
float pounds;
float gross;
float poundTot = 0;
ordercom = 'Y';
while(ordercom == 'Y')
{
printf("*******************************************************************************************************************\n");
printf("Determine What You Want To Buy\n");
printf("1) (a)\t Artichokes\t 3) (c)\t Carrots\n");
printf("2) (b)\t Beets\t 4) (q)\t Quit\n");
printf("*******************************************************************************************************************\n");
printf("\n");
printf("Select The Type Of Vegetable You Want:\n");
scanf("%c",&type);
fflush(stdin);
printf("Select The Amount Of Pounds You Want To Purchase:\n");
scanf("%f",£s);
fflush(stdin);
switch(type)
{
case 'a' :
{
gross = pounds * Artichoke;
ordercom = 'Y';
break;
}
case 'b' :
{
gross = pounds * Beets;
ordercom = 'Y';
break;
}
case 'c' :
{
gross = pounds * Carrots;
ordercom = 'Y';
break;
}
case 'q' :
{
ordercom = 'N';
break;
}
default :
{
ordercom = 'N';
break;
}
}
}
}
|
|
|
|
|
There is no harm in it, but in the cases for 'a', 'b' and 'c' you dont need to set ordercom = 'Y'; because it already has that value.
You should no longer need #include <conio.h> now that you got rid of _getch()
|
|
|
|
|
1 more thing I missed at a first glance.
For the case when the user presses q to quit, they still need to enter a float for the weight.
you should have the 2nd scanf inside an if to check for that
|
|
|
|
|
for the breaks in the switch statement, I could just see what was hapening
for the rest I placed a breakpoint on the line switch(type) so when it hit that I could see what the value of the variables were.
for the 2nd time in the loop type = '\n' (0x0A) when you hover over the variable name.
For the 'q' case for quitting I just know how scanf works, that it wont return until it gets a new line character, so another solution was needed
|
|
|
|
|
Before you start guessing, why not collect some information?
How about printing the values of type and pounds right after your scanf got them?
add a simple printf line, and you will probably know what is going on.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc,
I will do this on my next post. Thank you for the recommendation.
|
|
|
|
|
When I right-click an item in a list control, I'm using the following code to display a popup/context menu. That part works fine. I then want one of the items in that menu to be disabled. That part does not work.
BEGIN_MESSAGE_MAP(CMyView, CListView)
ON_UPDATE_COMMAND_UI(ID_SHOWDATA, &MyView::OnUpdateShowData)
END_MESSAGE_MAP()
void CMyView::OnRightClick( NMHDR *pNMHDR, LRESULT *pResult )
{
CPoint pt;
CMenu menu,
*pSubMenu;
menu.LoadMenu(IDR_LISTCTRL_POPUP);
pSubMenu = menu.GetSubMenu(0);
pt = GetMessagePos();
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);
*pResult = 0;
}
void CMyView::OnUpdateShowData(CCmdUI *pCmdUI)
{
pCmdUI->Enable(FALSE);
} As a matter of fact, OnUpdateShowData() does not get called until after I select the menu item, thus it has no chance to disable it. Any ideas?
Thanks.
- DC
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Before you call pSubMenu->TrackPopupMenu, you could call pSubMenu->EnableMenuItem[^] to initialise the menu as you please.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
That was it. Thanks.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
If you want to use your regular OnUpdateBlaBla functions, you could do something like
CCmdUI cmdUI;
cmdUI.m_pMenu = pPopup;
cmdUI.m_pSubMenu = NULL;
cmdUI.m_nIndexMax = pPopup->GetMenuItemCount();
for (int i = 0; i < pPopup->GetMenuItemCount(); ++i)
{
cmdUI.m_nID = pPopup->GetMenuItemID(i);
if (cmdUI.m_nID != ID_SEPARATOR)
{
cmdUI.m_nIndex = i;
cmdUI.DoUpdate(this, cmdUI.m_nID < 0xF000);
}
}
before calling TrackPopupMenu. This makes life easier if you have the same command in another menu and or toolbar button. Then you only need to maintain the logic in the OnUpdateBlaBla functions.
|
|
|
|
|
Niklas Lindquist wrote: cmdUI.DoUpdate(this, cmdUI.m_nID < 0xF000);
What is DoUpdate() ?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DoUpdate is an undocumented public member function of CCmdUI which makes it all happen. It will internally call your OnUpdateBlaBla function. That is how the framework uses it. I have used this construct for context menus in custom controls (runnng DoUpdate(GetParent(), ...) when there seemed to be no way of getting the automatic handling by the framework to kick in. The snippet comes from within an MFC class, but I can no longer remember which, but it works for me.
home
modified on Monday, January 17, 2011 4:15 AM
|
|
|
|
|
Well, there is always a lot of ways to skin a cat.
I would use my MEMC approach (Maximum Effect Minimum Code).
Your code does not use MFC update command UI mechanism, since you tell framework not to. Your code tells the framework to handle the popup menu directly in a view. View does not handle command update UI.
Change one line (or one expression) in your code to:
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, AfxGetMainWnd());
This will start proper menu handles search and UI updates.
You eliminate a need to handle disabling menu items before calling TrackPopupMenu; morover, if you add menu items and handlers you will never have to change a code that disables menu items before displaying popup.
JohnCz
MS C++ MVP
|
|
|
|
|
I'm looking for some VS c++ code that 1) preallocates a file 2) opens a preallocated file for sequential writing starting at the beginning of the file 3) writes(appends) ascii message strings to the file. Thanks
|
|
|
|
|
I'm not sure exactly what you mena by point 1, but opening a file for appending is quite straightforward, and writing text is even more so. Take a look at the STL file stream classes[^] or use the Createfile[^] and associated functions.
I must get a clever new signature for 2011.
|
|
|
|
|
You need to seek to what you want to be the end of the pre-allocated space, then set the EOF marker, then seek back to the start so you are writing from the beginning of the file, like so
HANDLE hFile = CreateFile("C:\\test", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
SetFilePointer(hFile, 4 * 1024 * 1024, NULL, SEEK_SET);
SetEndOfFile(hFile);
SetFilePointer(hFile, 0, NULL, SEEK_SET);
CloseHandle(hFile);
}
Edit:
I missed part 3...
quite simply seek to the end of the data in the file to append to it.
SetFilePointer(hFile, 0, NULL, SEEK_END);
SetFilePointer(hFile, nDataLength, NULL, SEEK_SET);
Writing to a file is pretty straight forward. You just need a buffer and the length of data you are writing
LPSTR szWrite = "hello world";
DWORD nLength = strlen(szWrite);
DWORD nBytesWritten;
WriteFile(hFile, szWrite, nLength, &nBytesWritten, NULL);
CloseHandle(hFile);
If you are writing strings in unicode you need to multiply the length by sizeof(wchar_t) or sizeof(TCHAR)
Finally, All file writes (and reads) are sequential for all APIs that I know of. It moves the file pointer to the end of the data you have just written (or read)
modified on Wednesday, January 12, 2011 11:23 AM
|
|
|
|
|
|
i am writing small utility there i wanted to show all bookmarks on right click of one icon(as a popupmanu)...it is working fine upto 2000 bookmarks
or more(depends)... i want to insert more bookmarks to popupmanu..
|
|
|
|
|
Your numbers are really too large for the mechanism you have chosen. Popup menus are designed to hold small numbers (fewer than 50) of items. If you want to display large lists then you would be better using some form of scrollable view or list. There are plenty to choose from among the windows controls.
I must get a clever new signature for 2011.
|
|
|
|
|
then how mozilla browser is showing more then 30thousand bookmarks on clicking Bookmarks Menu...?
|
|
|
|
|
yogish293 wrote: then how mozilla browser is showing more then 30thousand bookmarks on clicking Bookmarks Menu...?
Probably by writing some clever code. I did not say it was impossible, just not the best way to do things. You probably need to create a virtual menu which does not have any items in it but uses the owner draw feature to return the relevant items when the user clicks or scrolls into the menu. However, you should ask yourself whether your users will really have the patience to search through such a list for one single item.
I must get a clever new signature for 2011.
|
|
|
|
|
i tried to insert all menu item but its taking time to insert and after that my PC got restarted..
|
|
|
|
|
yogish293 wrote: i tried to insert all menu item but its taking time to insert and after that my PC got restarted..
Well that should give you a clue that those of us who are suggesting that you need to rethink your design may actually have a point.
I must get a clever new signature for 2011.
|
|
|
|
|
And you think it's a good idea ?
Anyway, it's probably some sort of "ownerdrawn" nenu.
I could suggest you have a look at the Firefox/Mozilla source code.
Watched code never compiles.
|
|
|
|
|
This is essentially a repost of the same question[^], were the answers there not helpful?
modified 13-Sep-18 21:01pm.
|
|
|
|