FAQ: Functions - Tackling Multiple Arguments

its so simple the std::string x is part of #include while int x is simple iostream member so you don’t have to write std::string x

Stuck on step 4.
I’ve done what I think it wants in the int main

int main() {

std::string my_name = “Thomas”;

int some_number = 5; // Change this if you like!

// Call name_x_times() below with my_name and some_number

name_x_times (my_name, some_number);

}

However, this is still saying I’ve done it wrong could someone tell me what’ve I done wrong?

I’ve done what you did but it still saying I’ve done it wrong?

Hi guys.
So I’ve no idea why this is wrong.
I checked previous exercises and it seems to be correct compared to previous tasks.

Add “” around Gilles.

1 Like

I oversaw the template where I had to replace “add your name here!” with my name, then I get to the same code as thomasswift, above this post, but also same problem:
./main.cpp: In function ‘void name_x_times(std::__cxx11::string, int)’:
./main.cpp:8:11: error: expected primary-expression before ‘int’
while(int x > 0){
^~~
./main.cpp:8:11: error: expected ‘)’ before ‘int’
./main.cpp:8:17: error: expected initializer before ‘>’ token
while(int x > 0){

Paste your code here. Easier to figure it out in an IDE.

No idea what’s done differently but I resetted the task and it worked now xD
Thanks a lot for the very fast response!

#include <iostream>

// Define name_x_times() below:
void name_x_times(std::string name, int x){
    while(x > 0){
        std::cout << name;
        x--;
    }
}

int main() {
  
  std::string my_name = "Gilles!";
  int some_number = 5; // Change this if you like!
  // Call name_x_times() below with my_name and some_number
  name_x_times(my_name, some_number);
  
}
2 Likes