Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / infinite loop

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. infinite loop
#3374
Posted by: 2004-02-15 05:55:25
hi
i am having a problem with an infinite loop
can someone check out the code and tell me
what is wrong with it...
 
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; i <= 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; 

for (int i = 1; i <= numberOfCandidates; i++) 
{ 
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; 
} 

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

i have attached my full source file and input file
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2022-12-9  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0