stuck with no errors

Evening guys. I am stuck and I have no clue where to turn to. I have looked through the logic of my code several times and the console doesn't throw any error messages, so I don't know where to go. The program builds correctly, however, when I go to run it, the entire program stalls and a windows error pops up. It basically says that the programs has stopped working. I'm not necessarily asking for handouts, but just someone to point me in the right direction. Show me what my mind is missing. Thanks ahead of time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "iostream"
#include "iomanip"
#include "fstream"
#include "cstdlib"
#include "string"

using namespace std;

const int NUM_OF_VOTES = 5;

void openAndStore(ifstream& in1, string names[],int votes[]);
void calculateLargestVote(const string names[], const int votes[], int length);
void calculatePercentages(const int votes[], double percent[], int length);
void printResults(const string names[], const int votes[], const double percent[], int length);

int main(){

string names[NUM_OF_VOTES];
int votes[NUM_OF_VOTES];
double percents[NUM_OF_VOTES];

ifstream input;

openAndStore(input,names,votes);
calculatePercentages(votes,percents,NUM_OF_VOTES);
printResults(names,votes,percents,NUM_OF_VOTES);
calculateLargestVote(names,votes,NUM_OF_VOTES);
}

void openAndStore(ifstream& in1, string names[], int votes[]){
    in1.open("F:\\school\\assign5input.txt");
    int length = 0;

    while(in1 && length < 5){
        length++;
        in1 >> names[length] >> votes[length];
    }

}

void calculateLargestVote(const string names[], const int votes[], int length){
    int largest;
    string temp;

    for(largest = 0; largest < length; largest++){
        if(votes[largest] > votes[length]){
            largest = length;
            temp = names[largest];
            cout << "The winner of the election is " << temp << "with" << largest << "votes";

        }

        length++;
    }
}

void calculatePercentages(const int votes[], double percent[], int length){
    int per, temp;

    for(int i = 0; i < length; i++){
        temp =+ votes[i];
    }

    for(int i = 0; i < length; i++){
        percent[i] = (votes[i]/temp) * 100;
    }
}

void printResults(const string names[], const int votes[], const double percent[], int length){
    cout << "Candidate" << setw(5) << "Votes Recieved" << setw(5) << "% of Total Votes" << endl;
    cout << endl;
    for(int i = 0; i < length; i++){
        cout << names[i] << setw(5) << votes[i] << setw(5) << percent[i] << endl;


    }

}


**update** i got it to output what I wanted with including:
in1 >> names[length] >> votes[length];
so it reads it in at least once. But still the windows error pops up. anyone have an idea why this is happening. I know this is an assignment, however, I already have solved the hw problem, I just don't get what's wrong.
Last edited on
check line 53 first, it might be one of suspects.
Topic archived. No new replies allowed.