|
Thanks, I am trying to implement your suggestions here is what I currently have..
#include <stdio.h>
#define MAXCOUNT 10
int main ()
{
int opselect;
int day, month;
printf("Enter a month between 1-12 :");
scanf("%d", &month);
printf("Enter a number for the day of the month");
scanf("%d", &day);
scanf("%d", &opselect);
switch (opselect) {
case 1:
if (month==2 && (day < 1 || > 28))
{printf("\nEnter a day between 1 and 28: \n ");
scanf("%d",&day);
}
case 2:
else if (month==4 || month==6 || month==9 || month==11)&&(day < 1 || day > 30))
{printf("\nEnter a day between 1 and 30: \n ");
scanf("%d",&day);
}
case 3:
else if (month==3 || month==5 || month==7 || month==10 || month==12)&&(day < 1 || day > 31))
{printf("\nEnter a day between 1 and 31: \n ");
scanf("%d",&day);
}
printf("The day accepted is %d\n",day);
return 0;
}
I am getting a ton of errors here, expected primary-expression before else, expected; before else.
What I am trying to do is based on the month input prompt for a the proper number of days in the month(2=28, 1=31 etc)and get in error message if you enter the wrong days(29 in Feb for example)
|
|
|
|
|
You are mixing a switch statement with if - else statements. That is not allowed. What is the opselect for? It seems unnecessary.
A more sophisticated solution would use an own function that checks if a day/month combination is valid:
if (!CheckDate(month, day))
{
printf("\nInvalid day/month combination. Please enter a valid day:\n");
scanf("%d",&day);
}
|
|
|
|
|
This assignment calls for a switch statement, I thought you needed opselect when using a switch? I tired using case:1, case 2 etc..., but I couldn't make it work. How do I do the switch w/o the if statements? Thank you so much for your help.
|
|
|
|
|
Thank you!!! Removed opselect and it works!
|
|
|
|
|
I donot know your C program.
Please talk me you realize the function.
I come from China.My English is not good.I hope you can understand my replay.
|
|
|
|
|
Dear all:
I get touch data by used HID.dll, it is raw data.
I wanna process the raw data, before send it to OS.
How can I send touch to OS, using postmessage or sendmessage?
if so, How can I use it?
Thank for your help, Victor.
|
|
|
|
|
Hello All, Could you help me speed up a program? It's designed to find the square root of a number.
<pre lang="c++">
#include<iostream>
using namespace std;
int main()
{
float a;
float c;
cout << "Square root calculator!" << endl;
cout << "Enter the number you want to square root" << endl;
cin >> a;
cout << "Enter an educated guess" << endl;
cin >> c;
cout << "The squareroot of " << a << " is: " << endl;
do
c = (c + (a/c))/2;
while ( c != a/c );
{ cout << c << endl;
}
return 0;
}
</pre>
My problem is that it get remarkably slow around 55ish. Any advice it appreciated
|
|
|
|
|
|
I'm guessing your issue is the while(). Comparing two floats can be tricky.
while ( c != a/c );
this[^] link may help.
|
|
|
|
|
That is the problem with the Babylonian method you have used.
Paul Hsieh has a very good webpage on everything about square roots but were afraid to ask.
http://www.azillionmonkeys.com/qed/sqroot.html[^]
It includes details most of the techniques from the standard C library, to the faster integers version that NVidia and Quake use.
|
|
|
|
|
hi..i have a requirement to write C/c++ application that converts Microsoft Word
(.doc) Documents into XML format. The application should be able to receive/open a Word document and save a XMl file with the same
name, but with the extension .xml..ur valuable suggestions will help me n will be appreciated..thanks
|
|
|
|
|
|
is there any library file to include in the code?..how to convert the entire docx formate?
|
|
|
|
|
You need to follow some of those links and do some research. As I said, reading Word documents in C/C++ is not particularly easy, unless you are familiar with C++/CLI, in which case you can use the Microsoft.Office.Interop.Word Namespace[^]
|
|
|
|
|
yes i have good experience in c++ but i have not worked on this requirements..if so i can read the data but question is how to store tht in xml format...suggestions will be greatly appreciated
|
|
|
|
|
krishnaprasad t wrote: how to store tht in xml format Store what? A word document is just like a book, lots of words separated by punctuation characters. In order to store that as XML you will need to design a set of rules and tags to split the data into logical sets. Each set would probably need some attrinutes, such as font (character set, height, fixed or true-type, bold, italic etc.). Writing the final XML is just a question of using one of the XML libraries available, either Microsoft or third-party.
|
|
|
|
|
thank u for ur reply..can u pls provide me links it would great help
|
|
|
|
|
I already gave you a link to the Word Interop. You should be able to search MSDN for yourself to find other pages of interest.
|
|
|
|
|
I'm thinking the easiest way would be to use Office Automation.
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
why do we use %u while outputting addresses????
|
|
|
|
|
I would say that %p is preferred. Maybe this[^] link will help.
|
|
|
|
|
%u is not a good choice for outputting memory addresses.
Personally, I use %p or %x for memory addresses.
Look here for printf type fields - printf Type Field Characters[^]
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how?
Remarks: I must use MFC, it's so hard to use pure Win32 API.
class CButton : public CWnd
{
DECLARE_DYNAMIC(CButton)
public:
CButton();
virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID);
UINT GetState() const;
void SetState(BOOL bHighlight);
int GetCheck() const;
void SetCheck(int nCheck);
UINT GetButtonStyle() const;
void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);
HICON SetIcon(HICON hIcon);
HICON GetIcon() const;
HBITMAP SetBitmap(HBITMAP hBitmap);
HBITMAP GetBitmap() const;
HCURSOR SetCursor(HCURSOR hCursor);
HCURSOR GetCursor();
#if (_WIN32_WINNT >= 0x501)
AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
#endif // (_WIN32_WINNT >= 0x501)
#if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
CString GetNote() const;
_Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
BOOL SetNote(_In_z_ LPCTSTR lpszNote);
UINT GetNoteLength() const;
BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
UINT GetSplitStyle() const;
BOOL SetSplitStyle(_In_ UINT nStyle);
BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
BOOL SetSplitSize(_In_ LPSIZE pSize);
CImageList* GetSplitImageList() const;
BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
TCHAR GetSplitGlyph() const;
BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
BOOL SetDropDownState(_In_ BOOL fDropDown);
HICON SetShield(_In_ BOOL fElevationRequired);
#endif // ( _WIN32_WINNT >= 0x600 ) && defined(UNICODE)
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
public:
virtual ~CButton();
protected:
virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
};
|
|
|
|
|
|