Hello everyone, I'm trying to figure out how to overload a function to solve the following problem:
"Write two functions with the same name (overloaded function) that print out a phrase. The first function should take a string as an argument, and print out the string once. The second function should take a string and an integer as arguments, and print out the string as many times as the integer."
I can't figure out how to get this to run though, here's the code that I have so far:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void print (string word)
{
print (word);
}
void print (string word, int number)
{
print (word, number);
}
int main(){
string word;
int number(0);
char c;
cout << "Please enter your word: " << endl;
cin >> word;
print(word);
cout << "\n";
cout << "Please enter a word and a number: " << endl;
cin >> word, number;
print (word, number);
cout << "\n";
return 0;
}
Any and all help would be cool!