# FAQ: Functions - Tackling Multiple Arguments

This community-built FAQ covers the “Tackling Multiple Arguments” exercise from the lesson “Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise Tackling Multiple Arguments

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I have made it to step 4 and I have to call name_x_times with arguments my_name and some_number within int main(). My problem is that when I type in the code it says that I need to type it within main() although I already am. What am I doing wrong? If somebody could please help that would be greatly appreciated.
#include

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

int main() {

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);
}

Your subtraction operation doesn’t look correct. Try to add another minus sign:

x - -;

1 Like

Thanks for the suggestion. Although I do already have two minus signs, it just does not appear that way in the text above. Any other suggestions?

Thank you for your help chipcoder46164, my problem with the code was that I needed to put (std::string name, int x).

2 Likes

just finished step 4 in this chapter

¨my code.

``````#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 = "Jonathan";
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);

}
``````

and cant move on the circle when pressing run is just rolling around,

zyph

4 Likes

Question: how come strings have to be defined with std::string x; , but ints can just say int x; without the std:: thing?? Which vars have to be defined before you give the type and which don’t??

Thanks,
Dawn

``````#include <iostream>

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

while (x > 0) {

std::cout << name << "\n";
x == x-1;

}

}

int main() {

int some_number = 5; // Change this if you like!
// Call name_x_times() below with my_name and some_number

}
``````

I have cleared steps 1 and 2. In step 3 I was told to print the string variable ‘name’ and then decrease the variable ‘x’ by 1. I wrote ‘x = x-1;’ and clicked the ‘Run’ button. It doesn’t give the correct result. But when I wrote x–; and clicked the ‘Run’ button, it gave the correct result. I remember that I used this type of syntax and got the correct answer in some other exercises and got the correct answer. Is the syntax ‘x = x-1;’ incorrect? (or) Is any other mistake present in my program?

I don’t understand why this code needs to have a while loop. And I especially don’t understand why the parameter inside the while loop says x > 0 when the loop keeps subtracting 1 from x. Why isn’t it x < 0?

Here’s my code:

``````#include <iostream>

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

int main() {

std::string my_name = "Riya. ";
int some_number = 5;

name_x_times (my_name, some_number);
}
``````

Any help would be greatly appreciated!

The code doesn’t “need” a `while` loop per se’, but this is one way to repeat a block of code a specific number of times. Your function `name_x_times()` takes 2 parameters. The first is the name to print to the console, and the second is the number of times to print it. The variable `name` will be assigned the name, and `x` will be assigned the number. `while` will repeat the code inside it’s code block `{ }` as long as the condition in the parenthesis evaluates to `true`. In your `main()` function you are calling the `name_x_times()` function with the arguments: `"Riya. "` and the number `5`, so the first time this line is executed: `while (x > 0)` `x` is `5`. `std::cout << name;` prints `Riya.` to the console, and x is decremented by 1. `while (x > 0)` is evaluated again, and since `x` is now `4` `Riya.` is printed a second time. This process continues until `x` is no longer greater than `0` resulting in this output:

Riya. Riya. Riya. Riya. Riya.

Hope this helps!

3 Likes

This makes much more sense, thank you so much for your help!!

1 Like

Is anyone else also experiencing bugs where you write valid code (even the same as the official solution) and it isn’t being accepted? For this exercise’s final piece I called the function as below

name_x_times(my_name, some_number);

and it wasn’t accepted. It was in the right place and everything. I’m a free member, but I won’t be coughing up the subscription price anytime soon considering how many bugs like this I’ve run into.

1 Like

I’m having an issue just with the first bit defining the function- for some reason the underscore in the name of the function make it stop working properly.

!
When i write it properly name_x_times it suddenly goes red and wont be recognised as a function. Does anyone know what is doing this and how to fix it

Is anyone having a problem where the program wont move forward? I click run and it just spins with no feedback

1 Like

Hello, @michaelschlemback779.

Welcome to the forum.

That usually happens when you have an infinite loop in your code. If you’ll post your code following these guidelines, we can take a look.

1 Like

Hi, for the example, why do we use if/else ? couldn’t we just say that
`total_included = price * tip + price ?`

the example :

``````double get_tip(double price, double tip, bool total_included) {

if (total_included) {

return price * tip + price;

} else {

return price * tip;

}

}
``````

The reason for this is if you want to include the price of the total + tip, or just calculate the tip.

2 Likes

I changed some_number to 10000 and I get this result. Why this happens? Why it shifts lines all the sudden?

1 Like

You are forgetting the `\n` character (which shifts the output to the next line). It should be in your `cout` statement within `name_x_times(string name, int num)`

Like ` std::cout << name << '\n';`

1 Like

I know about that. I don’t want “rand om 112!” and then next line but as it is right now. Problem as I see is that about first 1000 lines writes ok then suddenly shifts.