|
Note that I (a) read the forum guidelines about using the pre tag, (b) formatted your code so it is readable, and (c) have located my Caps Lock key.
I did however use multiple exclamation marks so it still looks like I was mad while typing.
main()
{
char ans;
printf("\n Do you want to play?(Y/N) ");
scanf("%c",&ans);
if ((ans == 'y'))
{
if (ans == 'y')
{
printf("\n Ok lets play! Press (Y) ");
}
}
scanf("%c",&ans);
if ((ans == 'y'))
{
if (ans == 'y')
{
printf("\n Press (Y) again ");
}
}
scanf("%c",&ans);
if ((ans == 'y'))
{
if ((ans == 'y'))
{
printf("\n Program Success!\n\n");
}
}
return 0;
}
Without running your program one line at a time, I don't know why it's passing over the middle test. But you are testing everything twice, which makes me suspicious.
I would single step through, and have a close look at the value of ans each time.
I would not be surprised to find that it is 'y' the first time it is called, and '\n' the second time, because you pressed Y and then pressed return.
But that's your voyage of discovery. Good luck!
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
the double "if"s are there because i am a n00b and really dont know, i just want a program to keep asking the users question for 4 terms and collect data, this is the only way i know how and it isnt working. I just started 1 week ago.
|
|
|
|
|
Don't worry about it. Once upon a time we were all beginners. Heck, in the majority of software stuff, I *still* am a beginner.
Don't ask me to knock up an e-commerce website. I just about know the name of php/mysql and that's it. I like to think I could learn, but even so...
The big tip I can give you is to single step through your code, keeping an eye on the contents of the variables. The double testing for y is not good though - fix that now before you get into bad habits!
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi,
in one weeks time, you could have read an entire tutorial book from cover to cover; that would have saved you a lot of time and problems, and given you lots of insight and knowledge already.
BTW: when you call scanf twice, it needs input twice. Did you provide a double 'y'? how about newline stuff?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Iain Clarke wrote: Note that I (a) read the forum guidelines about using the pre tag, (b) formatted your code so it is readable, and (c) have located my Caps Lock key.
I did however use multiple exclamation marks so it still looks like I was mad while typing.
That's
F A N T A S T I C !
No need to say I've added it to the CP's Memorable Quotes page [^].
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]
|
|
|
|
|
lincoding wrote: CAN ANY ONE TELL ME WHY IT SKIPS THE THIRD "IF" AND GOES ON TO THE FORTH?
Why not set a breakpoint on that line and check the value of ans ?
You might also want to check out fflush().
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Try using else after your if 's - if (sorry) it doesn't do the 'if ' it will then perform the 'else ' and you can put in a line to print out 'ans' to the screen to see what it really is.
One little thing, Users are a bit odd, if you ask them to type 'Y' upper case, then test for 'y' lower case you might find they didn't do what you expect (they never do).
You could test for if(ans == 'y' || and == 'Y') just in case.
|
|
|
|
|
Instead of this:
scanf("%c", &ans);
use this:
ans = getch();
include conio.h for that.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi all,
i have and diaog box here i m suing a List Ctrl, on dialog box i have button on click event of this button i m processed a for loop and fill the entries in List Ctrl that is takes so much time.
so the cursor moves very fast and dialog box is hang.
i want when i click the button any msg box or any thing else without having any button is displayed,
that is having information like "Please wait...",and process continue in background.
when process finished than this msg box automatically closed.
please tell me how can i do this.
if possible please explain me with any example.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
modified on Friday, February 20, 2009 11:36 PM
|
|
|
|
|
Usually moving the background processing in a worker thread [^] will do the trick.
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]
|
|
|
|
|
Here i m using a worker thread but its gives error.
i want to insert values in list ctrl when loop is running.
may be i m used the thread in improper way.
please can u tell me how can insert values in list ctrl of main dialog with using of thred.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Your worker thread should post a message to the main (the GUI) one and let the latter updating the list.
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]
|
|
|
|
|
Is MFC out of date? Should I learn it by heart,any body can help me?
|
|
|
|
|
Archy_Yu wrote: Is MFC out of date?
I dont think so, since VC2008 is having MFC Feature Pack...
Archy_Yu wrote: Should I learn it by heart
I am against learning something byheart... because RAM in our brain is precious, so dont waste its space... (I like Sherlock Homes)
Archy_Yu wrote: any body can help me?
What help you are expecting?
- ns ami -
|
|
|
|
|
Anyway, you have to learn (at least) about all varieties of mud you may find in England's countryside.
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]
|
|
|
|
|
That's a nice answer... Hope you are much interested of him...
- ns ami -
|
|
|
|
|
i am very happy, you could answer my question. i am a Chinese,and not very much good at English,usually i would ask my tecknoly problem on MSDN. but you answer just encourage me to ask question on CodeProject,and i am determined to study English very good to
use it as fluent as my mother tong.
enjoy you answer.i would like make a friend with you.
|
|
|
|
|
Archy_Yu wrote: i am a Chinese,and not very much good at English
You could really convey what you need... so not that much bad in language...
Archy_Yu wrote: i would like make a friend with you
I am very happy to get a friend from a great country...
- ns ami -
|
|
|
|
|
Hey ppl,
I got stuck with this pure thing.. I got a class which contains pure functions:
virtual void OnMouseDown(int Button, int X, int Y) = NULL;
virtual void OnMouseMove(int X, int Y) = NULL;
virtual void OnMouseUp(int Button, int X, int Y) = NULL;
virtual bool OnRender(void) = NULL;
And I have a derived class which overrides these methods:
bool OnRender(void);
void OnMouseDown(int Button, int X, int Y);
void OnMouseMove(int X, int Y);
void OnMouseUp(int Button, int X, int Y);
But the compiler says:
Error 5 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared
Error 6 error C2535: 'void CXWindow::OnMouseMove(int,int)' : member function already defined or declared
Error 7 error C2535: 'void CXWindow::OnMouseUp(int,int,int)' : member function already defined or declared
Error 12 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared
Ok! if I remove my override functions compiler says:
Error 22 error C2259: 'CXWindow' : cannot instantiate abstract class d:\my codes\chess\chess\dx.cpp 16
Since I do not override them it says this is abstract!
Ok one more thing that i've noticed: OnRender method is also defined pure abstract but I do not get any error about that! Only difference is it does not contain any parameter and returns bool...
thank you in advance...
|
|
|
|
|
Some of the function names are the same as those used by MFC.
Change the names and it should work.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
wow you are totaly right...
i did change their names and it worked...
i do not use MFC in my app but still I add windows.h, windowsx.h..
anyways... thank you very much..
|
|
|
|
|
dehseth wrote: virtual void OnMouseDown(int Button, int X, int Y) = NULL;
virtual void OnMouseMove(int X, int Y) = NULL;
virtual void OnMouseUp(int Button, int X, int Y) = NULL;
virtual bool OnRender(void) = NULL;
Pure virtual functions should be assigned 0 not NULL . It's merely a coincidence that NULL has a value of 0 .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi everybody
I am drawing a graph.The Y Axis of the graph is derived from CWnd and is attached to the left end of my view class which is derived from CSrollView.
So while horizontal scrolling of my view class i want to keep the Y Axis stationary.
Can anybody help me to prevent this particular portion of the view from being updated while horizontal scrolling.
Thanks and regards
Deepu
|
|
|
|
|
I haven't tried, but I felt that it will work. (It's a little bit complicated.)
Make a region with a rectangular hole for the Y Axis window and set it to the scrollview. So you will get space to place the Y Axis window. The parent of Y Axis window should be the same of that of scrollview. Position the Y Axis window right there.
Steps to make such a region can be as follows
1. Create a rect-region with size of scrollview.
2. Create another rect-region with size and position of Y Axis window.
3. Combine both regions
Apply this combined region to scrollview.
- ns ami -
|
|
|
|
|
Thanks for the reply
I did the same before.
I am having a class CGraphicsView derived from CScrollview
Then CYAxis derived from CWnd
Then i am dynamically creating the CYAxis to CGraphicsView in OnCreate function.
Then in OnDraw function i am displaying the CYAxis.
But the problem i am facing is that while horizontal scrolling the YAxis values is getting disturbed ie is not aligned properly.
|
|
|
|