please correct

I can't seem to solve this code problem of shuffling football team together
wat did i do wrong. it saying, expected unqualified-id before 'for'

#include <iostream>
#include <string>
#include <array>
using namespace std;


string teams[4] = {"Wolves", "Dream FC", "United DC", "Mkeys"};
for (string home_team = teams) {
for (string away_team = teams) {
if (home_team != away_team) {
cout << home_team + " Vs " + away_team;
}
}
}
https://en.cppreference.com/w/cpp/language/range-for
Maybe you want a : instead of = in your range-based for loops.
Don't pass string by value unless you really need a copy to be made - pass by ref or const ref.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main()
{
	const string teams[] {"Wolves", "Dream FC", "United DC", "Mkeys"};

	for (const string& home_team : teams)
		for (const string& away_team : teams)
			if (home_team != away_team)
				cout << home_team + " Vs " + away_team << '\n';
}




Wolves Vs Dream FC
Wolves Vs United DC
Wolves Vs Mkeys
Dream FC Vs Wolves
Dream FC Vs United DC
Dream FC Vs Mkeys
United DC Vs Wolves
United DC Vs Dream FC
United DC Vs Mkeys
Mkeys Vs Wolves
Mkeys Vs Dream FC
Mkeys Vs United DC

Thanks so much seeplus and salem c. much appreciated
Topic archived. No new replies allowed.