|
|
hi
i am having a problem with an infinite loop
can someone check out the code and tell me
what is wrong with it...
[code]
int main()
{
int numberOfResponses; //number of responses for candidates
int accumulator = 0; //adds up total number of votes
do
{
char* stateName = new char[30]; //char pointer array for stateName
char* dateOfPrimary = new char [30]; //char pointer array for date of primary
cin.getline(stateName,30) ;
cin.getline(dateOfPrimary,30);
cin >> numberOfCandidates;
primaries NewPrimary(stateName,dateOfPrimary);
cout << NewPrimary <<endl;
delete="" []="" statename;=""
delete="" dateofprimary;=""
for="" (int="" i="0;" <="numberOfCandidates;" i++)=""
{=""
char="" nameandspent[50];="" char="" array="" for="" name="" and="" money="" spent=""
cin.getline(nameandspent,50);=""
if="" (i="" !="0)"
candidates="" newcandidate(nameandspent);=""
cout="" <<="" newcandidate="" endl;=""
}=""
results="" newresults;=""
int="" votes;=""
cin="">> votes;
accumulator = accumulator + votes;
NewResults.voteArray[i-1] = votes;
}
NewResults.totalNumberOfVotes = accumulator;
NewResults.percentage();
cout << NewResults << endl;
cin >> numberOfResponses;
for (int i = 0; i <= numberOfResponses; i++)
{
int c, i, v;
cin >> c;
cin >> i;
cin >> v;
election MyElection(c,i,v);
}
char blank[5];
cin.getline(blank,5);
cin.getline(blank,5);
}while(!cin.eof());
return 0;
}
[end code]
the INPUT is like this:
Iowa
January 19, 2004
6
Kerry 50000
Clark 20000
Dean 40000
Gephardt 20000
Lieberman 10000
Edwards 40000
1128
83
540
318
60
957
15
1 2 8
3 2 5
1 3 6
1 1 6
6 1 7
5 2 5
2 4 7
4 3 6
6 2 7
1 4 9
6 4 7
3 4 7
2 3 6
1 4 8
4 2 6
New Hampshire
January 27, 2004
5
Kerry 500000
Clark 200000
Dean 400000
Lieberman 100000
Edwards 50000
84229
27254
57788
18829
26416
25
1 2 8
3 2 7
1 3 6
1 1 7
3 1 7
5 1 7
2 4 6
5 3 6
4 1 4
1 4 9
3 4 8
1 2 7
2 1 7
3 2 8
4 2 6
5 2 8
2 2 6
3 3 7
1 2 8
2 3 7
3 2 7
4 4 6
5 4 7
2 2 6
3 3 6
ps....if i use just one set of data...my program works...but when i add another set of data....such as above (there are two) one for iowa and one for new hampshire...it keeps going on forever...help please
|
|
|
|
|
Which version of VC++ are you using. I'm assuming VC6.
After a quick glance, I think your problem is
for (int i = 0; i <= numberOfResponses; i++) <br />
{ <br />
int c, i, v; <br />
cin >> c; <br />
cin >> i; <br />
cin >> v; <br />
election MyElection(c,i,v); <br />
}
You are redeclaring the variable i and then setting it to a different value. I think this may be throwing off your loop.
VS.NET wouldn't let the code compile, but VS6 would.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
When you use iostream and some read function fails, a failbit is set to the input stream. Any subsequent readings will simply return without doing something. Hence you will never pass the eof of the input stream.
Because you declare a cycle iterator inside the cycle (as Michael P. Butler wrote), this cycle probably doesn't repeat numberOfResponses -times. And the subsequent read operations probably read different types, that they expect, so the read operation fail.
The solution is:
* check whether cin.fail()
* if yes, restore the failbit by cin.clear()
Robert-Antonio
"Friends come and leave, but teddybears stay in forever."
|
|
|
|
|
Can u make a graphic interface which interacts with some buttons ? .. for eksample if u have a dialog with some balls and a button, and when u press the button the balls start moving .. what should i look for? .. i tryed working with SDL but that dosent work for MFC or does it?
|
|
|
|
|
The interaction of a GUI, in it's simplest form, is implemented by a series of WM_PAINT calls.
You can, for example, create two integer variables xPos and yPos that determine the position of a ball when it is drawn on-screen. Then, a click of a button sends these balls into a continous WM_PAINT loop, and during each iteration of the loop, the positional variables are altered, thus causing the ball to "move".
This approach, however, will result in your application looking pretty much frozen, as it will stop answering to other messages during the animation loop. I suggest you dwelve into concepts like Direct3D and OpenGL if you want to draw fast graphics without obscuring the messaging queue.
Unfortunately I cannot provide you with a code example..
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I'm not sure about SDL, but if you need a lot of control you can use DirectX. If all you need to do is use buttons and GUI components try RHW vertices and textured quads. It's a fair amount of work, but worth it once you've got it going. Some of the game programming sites www.gamedev.com and www.flipcode.com are good resources.
Integrating DirectX with MFC[^]
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
i wrote a program that monitors the printer. and save how many pages were printed.
but i have a problem. Word XP has a bug, when i print a multiple copies (more than one), by using GetJob function, i don't get the number of copies. the dmCopies value in DEVMODE struct, is 1.
i can't sell my program when this bug not solved! ...
i thought about somehow to read the spooler file, but this is not generic...
somehow, Word XP sends the right number of copies to the printer, because the printer is printing the right number of copies.
but this info is not changed by Word XP in DEVMODE.
do you have any idea how to solve this?
please...
this is very important to me...
thank you very much.
|
|
|
|
|
Just a thought, but is Word maybe doing collation itself, by sending pages multiple times (instead of relying on the printer to collate)? Try printing with and without collation enabled in Word, and see if that has any effect...
---
the work, which will become a new genre unto itself, will be called...
|
|
|
|
|
my program use the FindNextPrinterNotification (i don't remember it exactly) to know when the user send something to the printer.
after that i'm waiting until it stop spooling and i pause the job and then i use GetJob() to get the information about this job.
there is the problem.
i don't get the correct number of copies if the program is Word XP. with all the other it's just fine.
i tried to change some of the Word XP options but nothing...
i think it's because Word XP don't use the generic Print Dialog like all other windows programs does.
if you have any idea...
i'm totally desperate.
please...
please...
thanks,
|
|
|
|
|
How can i from VC++ application receive text under the mouse pointer in web browser window , for example.
thank you in advance !
|
|
|
|
|
using Visual C++ 6.0 with MFC
I am using a RichEdit control as a simple editor.
I am not using word wrap so the lines extend beyond the width of the control.
Problem:
I often find that if I replace highlighted text or even just add text to an existing line the new text is not displayed. It appears to not repaint correctly. I need to insert a space at the beginning of the line, or otherwise make it move to get it to display the change.
Also often the scroll bars do not display even though the text is wider than the control. When the redisplay is corrected the scroll bars are also displayed.
Is there a simple solution to this?
Sara
|
|
|
|
|
Hi all,
I am building an application which has a log-in dialog. I need the menu and toolbar selections to be diabled in the beginning and i need them to be active only when a valid user logs in.
Can you please help me in achieving this?
Regards
Krugger
Krugger
|
|
|
|
|
Assuming you are using MFC, have a read about ON_UPDATE_COMMAND_UI.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
Hi all;
I have an application which has a log-in menu. The whole stuff works fine but the only problem is that if a user hits "Escape" while my log-in menu is on, the thing just disappears leaving him/her with all the program functionality without even logging on the system!! Obviously something's going wrong! Can u please help me to stop the dialog from closing when i hit Escape.
Thank you guys;
Regards
Krugger
|
|
|
|
|
|
I use this approach:
BOOL CDejavuDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN))
return FALSE;
return CDialog::PreTranslateMessage(pMsg);
}
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
I am making a dialog box with MFC. I wan't to make a minimize box at design time. When I right click the dialog in the .rc and go to properties, the minimize box field is greyed out at "false". Anyone know how to make a minimize box? Any help is appreciated.
-Dev578
|
|
|
|
|
In order to have a minimize box option available, you must have the system menu flag set to true. This means the minimize, maximize and close buttons get drawed on the dialog caption. You can then set the minimize and maximize boxes on and off as you please, but you can't remove the close button.
If you only want the minimize button, you can draw it yourself on the dialog by overwriting the WM_NCPAINT message. To implement it, enable dialog title bar without the system menu, add a CButton for the minimize button, then override CWnd:OnNcPaint, allow the framework to execute the base class drawing first so that the standard frame is painted. Then draw/place the button.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi .. if I want to open a SDL application from a MFC dialog based application what should i then do? .. rigth now i am just opening the .exe of the SDL application but then i cant share some values i need ..
|
|
|
|
|
There are several solutions. One solution is file-mapping. Another solution is via message - WM_COPYDATA.
Kuphryn
|
|
|
|
|
Hi .. if u launch a .exe file from a application it opens the .exe file over the application so its not visible .. is there a way to get the .exe file to open next to the application window so both windows are visible ?
|
|
|
|
|
Definitely.
One solution is CreateProcess(). Analyze the STARTUPINFO parameter.
Kuphryn
|
|
|
|
|
I am tried to wrote a program that listing windows created by a specified process, it base on EnumWindows And EnumChildWindows. But it does not exactly.
Spy++ show me that the top-level window of the process' "first-child" property is 0x00000000, but serveral child-window's "parent" is pointed to the top-level window.
Thanks a lot for any advices.
|
|
|
|
|
This is just a stab in the dark but did you try to get the desktop window and enumerate its children??
John
|
|
|
|