inconsistency in methods

EDIT: I'm retarded NWM

First of all sorry for all the Swedish variables they were name specified for the assignment(doing a course to learn programming)

anyway I'm doing a program that handles Transactions in a TransactionsList and assigns values to Persons in a PersonList
(I'm still not super comfortable with aggregates)

a single transaction might look like:
Date type name amount #friends Friends
151209 car Johan 100 3 f1 f2 f3

now I can find my friends in a friends array but when used in "aerSkyldig" AKA OwsMoney I can only find them sometimes depending on their index in the array on each recite/transaction

Methods taken out of context but am I missing something here or does my problem lie elsewhere?

a successful read might look like:
Friend not found
friend not found
friend found //found in finnKompis/FindFriend
found //found in aerSkyldig/OwsMoney

but otherwise it'll look like
friend not found
friend found //found in findFriend but not in other method
friend not found

where the name is found in the Transaction but not in the TransactionList

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
 
Class Transaction::findFriend
bool Transaktion::finnsKompis(std::string namnet) {
	bool found = false;
	for (int i = 0; i < ant_kompisar; i++) {
		if (namnet == kompisar[i]) {
			std::cout<<"Friend found" << std::endl;
			found = true;
		}
		else {

			found = false;
			std::cout << "friend not found" << std::endl;
		}
	}
	return found;
}

//Class TransactionsList::OwsMoney
double TransaktionsLista::aerSkyldig(std::string namnet) {
	
	double ows = 0, totOws=0;

	for (int i = 0; i < antalTrans; i++) {
		
		if (trans[i].finnsKompis(namnet)) {
			std::cout << "found" << std::endl;
			ows += trans[i].haemta_belopp();
			ows /= trans[i].haemta_ant_kompisar();
		}
		totOws += ows;
		ows = 0;
	}

	return totOws;
	
}


If anyone could point me in he right direction I'd appreciate it!
Last edited on
I went to bed and noticed I'm returning false each time the name I'm looking for isn't in the last itteration...sleep is good
Topic archived. No new replies allowed.