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

change the x- into x–

I can’t get past the first step and don’t know why. The first step is to:

1.Define a void function name_x_times() that takes two parameters:

  • a string name
  • an integer x

Codeacademy keeps telling me that when I type my:
void name_x_times(std::string name, int x) code, it asks the question:

Is name_x_times defined as a void function with two arguments?
When I click view solution and even copy the code, reset the exercise, and paste it the the code seems to run, but codeadademy doesn’t give me the checkmark to indicate completion. Here’s my code:
#include

// Define name_x_times() below:
void name_x_times(std::string name, int x);

int main() {

std::string my_name = “Add your name here!”;

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

// Call name_x_times() below with my_name and some_number

}