FAQ: Functions - Tackling Multiple Arguments

#1

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:

Learn C++

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 (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.

Ask or answer a question about this exercise by clicking reply (reply) below!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

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!

#2

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() {

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

name_x_times(my_name, some_number);
}

#3

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

x - -;

#4

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?

#5

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

1 Like
#6

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,

thanks in advanced,

zyph

#7

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