I am trying to make a small program that gets the a value that a user inputs and then prints "Hello" that many times. I am trying to do it through different functions but I have been stuck on this for some time. Any feedback is appreciated.
return sum;
Returning from main terminates program.
What you want to do is to call hello function with an argument.
If you want to define some function after the main function you need to write function prototype before main.
#include <string>
#include <iostream>
#include <cmath>
usingnamespace std;
int hello(int); // function prototype
int main()
{
int numO, numT, sum;
cout << "input two number" << endl;
cin >> numO >> numT;
cin.ignore();
sum=numO+numT;
hello(sum); // call the function with an argument
return 0;
}
int hello(int sum)
{
for(int i = 1; i <= sum; i++) // we can use that argument in our function
// or for(int i = 0; i < sum; i++) but not for(int = 1; i < sum; i++)
cout << "Hello!" << endl;
return 0;
}