0

What’s wrong with this code?

I made this simple code to test out functions but it shows no output. #include <iostream> using namespace std; void printName (string name [], int size) { for (int x = 0; x > size; x++) { cout << name [x] << endl; } } int main() { string myArr [] = {"David", "Ryan", "Bob"}; printName (myArr, 3); return 0; }

17th Aug 2018, 10:59 AM
aFlyingGibbon
2 Respuestas
+ 1
your for loop: for (int x = 0; x > size; x++) { you need to change x > size to x < size because the way you have it the loop doesnt run. so it should be: for (int x = 0; x < size; x++) {
17th Aug 2018, 11:04 AM
Mooaholic
Mooaholic - avatar
0
Thanks I fixed it now!
17th Aug 2018, 11:09 AM
aFlyingGibbon