Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

infinite loop

Status
Not open for further replies.

4ize

Programmer
Feb 14, 2004
1
US
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; 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; 
} 
[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
 
Please post your code and data between

Code:
[tt][[/tt]code]
// your code here
[tt][[/tt]/code]
tags.

[end code] is not a recognised tag.

Use the preview button to make sure the presentation is as you expect.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top