|
Now that the program adds the numbers and provides the sum at the end, I need to provide a means of displaying how many times a user input something.
The example output would be:
Sum = 134
Total numbers of inputs = 8
So I have been looking to find something on counters. I have looked at multiple web sites yet again and can not find anything. I have fixed my previous code and it is listed below. Once again, I DO NOT WANT THE ANSWER, I WANT THE REFERENCE SO I CAN LOOK IT UP MYSELF. Being pointed in the right direction helps me most.
Thank you all again.
#include <iostream>
using namespace std;
int main()
{
int userinput;
int sum = 0;
int count = 0 ;
cout << "Roberts Number program v1" << endl;
cout << endl;
cout << endl;
cout << "When you are finished, enter '0'" << endl;
cout << endl;
while (userinput != 0)
{
cout << "Input a number, then press enter. " ;
cin >> userinput ;
sum += userinput;
}
cout << "The sum is:" << sum << endl;
return 0;
}
|
|
|
|
|
rbwest86 wrote: counters
A counter is just a variable that holds a number. So per your requirement I will reword it to provide the hint that you need...
Each time that the user enters a number, increase the counter, then when the user is done entering numbers, output the number of times that the user entered a value.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hello people!
Here's a simplified version of what i am trying to do (sorry for the long code):
class CTestClass
{
public:
void AMethod(int x);
BOOL BMethod(char y);
};
template<typename TParamType>
class TTestTemplate
{
typedef void(CTestClass::* LPFN_AMETHOD)(TParamType);
typedef BOOL(CTestClass::* LPFN_BMETHOD)(TParamType);
bool fIsAFn;
union {
LPFN_AMETHOD fnA;
LPFN_BMETHOD fnB;
};
public:
TTestTemplate(LPFN_AMETHOD pFn):fnA(pFn), fIsAFn(true ) {}
TTestTemplate(LPFN_BMETHOD pFn):fnB(pFn), fIsAFn(false) {}
void Call(CTestClass *pInstance, TParamType val);
};
template<typename TParamType>
void TTestTemplate<TParamType>::Call(CTestClass *pInstance, TParamType val)
{
if (fIsAFn) (pInstance::*fnA)(val);
else (pInstance::*fnB)(val);
}
At the highlighted line i am getting an INTERNAL COMPILER ERROR, i googled around and this seems to be a bug in the compiler (am not absolutely sure though), so my question is: does anyone maybe know of any workaround for this? I am using VC++ 2003 (using a newer version of VC++ is sadly not an option since this is out of my hand, i am stuck with it). If i could somehow get it to work it would simplify my life a lot...
[ANSWER] Ok, seems to be that i am trying to call the methods thorough the pointers wrong, if i use this:
(pInstance->*fnA)(val); instead of the :: version it compiles and runs fine. So i guess the bug is that it does not give any usefull error not that it can't "eat" function pointers and templates together. What are the odds...[/ANSWER]
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
modified on Tuesday, January 19, 2010 12:56 PM
|
|
|
|
|
pInstance is class instance. Did you ever see any people use it like:
pInstance::
For a class pointer, using "pInstance->" is correct.
"::" is just for "class" or "namespace"
|
|
|
|
|
Yes, as you can see on my post i realized that already, but thank you, i would have noticed that sooner if the error message i got would have been something like "don't use :: on that, you moron" instead of "duh, compiler is broke, boohoohoo"...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Does anyone have the book "Programming Microsoft Visual C++ 5th Edition, David J. Kruglinski, George Shepherd, and Scot Wingo"? I bought the book secondhand but it never came with a CD because it was lost. I manage to type up the code listings to try out the examples. However am stuck on chapter 12: Windows Message Processing and Multithreaded Programming. Apparently the example 12B & 12C relies on 12A code, however it doesn't do complete listings for 12B or 12C but vaguely describes changes. I don't think it's explained all changes because I can't get it to compile.
Just wondering if anyone had the CD (code listing files) for this book?
|
|
|
|
|
Hi all i am using the method InternetOpenUrl with a callback
then i can tell when status complete that proxy authentication is needed
in MSDN it says to call InternetSetOption with the proxy user name and password and then call resend
the problem is that i don't know how to call resend because if i call InternetOpenUrl again then it says again when complete that proxy authentication is required
???
can any1 help?
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
the trick was not to call again internetopenurl (since it opens a new session), but to call httpsendrequest...
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hi.
I am trying to stream audio with waveOutWrite(). I have a server which gets continuously packets with voice data. What I do is playing data with waveOutWrite() and then in callback function when the playing is done I call to waveOutWrite() with next packet (there is no such situation that there are no ready packets). The problem is that because of a very small size of packets and so a large amount of packets there is a small gap between them, so I dont get a clear playing. How can I stream it more smoothly?
I am not a genius, but shed more sweat!
|
|
|
|
|
When do you start to play a new packet?
In general you should use at least two buffers where one is filled and queued for play with waveOutPrepare & waveOutWrite while the other buffer is still playing.
I prefer 5 or more buffers for that because also with 2 buffers you hear sometimes a gap.
Maybe you could post your callback or the function where you prepare and write.
Greetings
Covean
|
|
|
|
|
thx!
I am not a genius, but shed more sweat!
|
|
|
|
|
Could you give me your code on how to play multi buffers with waveOutWrite?
I am not a genius, but shed more sweat!
|
|
|
|
|
I would take a look at this CodeProject-Article.
It helped me to work out how to handle audio playback.
Hope that helps.
Greetings
Covean
|
|
|
|
|
Aric Green wrote: The problem is that because of a very small size of packets and so a large amount of packets there is a small gap between them...
As well as multiple buffers as suggested above by Covean, you should try to use larger packets, to reduce the amount of unnecessary processing you're doing. Using very small packets will be more likely to cause you problems, as you're experiencing.
Days spent at sea are not deducted from one's alloted span - Phoenician proverb
|
|
|
|
|
Thank you answay!Covean's reply just to the point.I found my fault,thx again!
I am not a genius, but shed more sweat!
|
|
|
|
|
hi
can the tutorial in learn vc++ 21 days about socket programming work without the code related to SetParent(this). I am implementing the same program but not in a dialog or a view class.
thanks
Darshi
|
|
|
|
|
Yes it will work fine until the GetParent() call (i.e. dumb question-dumb answer)...
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]
|
|
|
|
|
well u mite think its dumb.
The original code goes like this
void CMySocket::SetParent(CDialog *pWnd)
{
m_pWnd = pWnd;
}
<pre>
I wanna modify it to
void CMySocket::SetParent(CWeigh *pWnd)
{
m_pWnd = pWnd;
}
Weigh is a class created for my program which has no base class. I have made all the declarations correctly. When i add the header file of CWeigh Class to the header file of Socket class i get errors.
Plz help, and hence the question of eliminating SetParent
|
|
|
|
|
OK, things are getting a little better now.
In the original code (you have it, I haven't) the CMySocket::m_pWnd member is possibly a pointer to a CDialog object while you're passing a pointer to CWeight one, hence (probably) the compile errors.
To get better help, you should post, at least, the exact error message and the line of code wherein the error occurs.
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 have included the header file for my weigh class as follows
#include "Weigh.h"
#if !defined(AFX_MYSOCKET_H__57CF680B_2F58_4A22_81FF_1A8C4841E38E__INCLUDED_)
#define AFX_MYSOCKET_H__57CF680B_2F58_4A22_81FF_1A8C4841E38E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
I have declared the pointer and the setparent class as follows
void SetParent(CWeigh* pWnd);
CWeigh* m_pWnd;
I am getting errors which state
error C2061: syntax error : identifier 'CWeigh'
|
|
|
|
|
It looks like you included Weigh.h inside a header file (usually you include header inside source, i.e. cpp files) and that you've included it before the multiple inclusion guard (the block starting with #if !defined(...) , ending with #endif ), hence your compilation error may occur because of header multiple inclusion. Do the following change (if you really need to include the header inside the other header... )
#if !defined(AFX_MYSOCKET_H__57CF680B_2F58_4A22_81FF_1A8C4841E38E__INCLUDED_)
#define AFX_MYSOCKET_H__57CF680B_2F58_4A22_81FF_1A8C4841E38E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Weigh.h"
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]
|
|
|
|
|
Hi ALL,
Which one is easier to develop a GUI.Is it VC++(MFC) or is it VC++/CLI(i.e.VC++.NET).Please advice.
Thanks,
ashwath.
|
|
|
|
|
I would not use Managed C++ to build a GUI . I would use instead C# . That said, MFC is quite powerful (nothing is really easy when talking about Windows programming).
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]
|
|
|
|
|
Agree that one should not use Managed C++ for building GUI. Managed C++ is mainly for compiling legacy C++ code, where performance is not an issue. Or wrapping native C++ code as standard .NET classes.
I would choose Winforms/C# over MFC/C++.
|
|
|
|
|
Starting from what level of development skills ?
IMO, they are both equivalent, have a look at your requirements and match them to what MFC and .NET (forms) have to offer.
M.
This signature was proudly tested on animals.
|
|
|
|