How can I only call the function once

closed account (E8A4Nwbp)
This is my simple struct program
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
struct outlet
{
	string name;
	bool bankrupt;
	int worth;
};
void isbankrupt(outlet shop)
{
	if(shop.bankrupt)
	{
		cout<<"Name: "<< shop.name<<endl;
		cout<<"Worth: "<< shop.worth<<endl;
	}
	
}
int main(int argc, char *argv[]) {
	outlet Asda{"Asda", false, 400};
	outlet Tesco{"Tesco", false, 700};
	outlet Lidl{"Lidl", true, 600};
	
	isbankrupt(Asda);
	isbankrupt(Tesco);
	isbankrupt(Lidl);
	
	
	return 0;
}

How can I call the inbankrupt() function once?
Last edited on
Astra wrote:
How can I call the inbankrupt() function once?

Delete lines 22 and 23.
You could also use an array of structs, and then use a loop to call the isbankrupt() function once for each struct[i].
closed account (E8A4Nwbp)
Delete lines 22 and 23.
Are you joking?
If you delete those lines ... you will only be calling it once. Obviously. On line 21.

If you would like something else, please write a clearer question.
"isbankrupt" as the name for a function that simply prints information is a bad name, imo.
Normally "isX" functions return a boolean or something of that nature.

Other than that, yes use a array/vector, as xmrfate said.
closed account (E8A4Nwbp)
Thanks @Ganado and @xmrfate

apologies for not having an elucidated question, @lastchance .
No problem. I'm glad we could help!
Topic archived. No new replies allowed.