I'm trying to create a function that will take the input from the user and create an inverted triangle. However, I'm getting an error at the end of my function(line 29) that states "control reaches end of non-void function."
I think it has something to do with a return value but I'm not sure. Also, when I change int number
inside my function to int num
I get an error saying,"Redefinition of 'num'."
Please help. Explain what the error is occurring and how I can fix it.
Thank you.
#include <iostream>
using namespace std;
int row(int num)
{
int number;
int decreasedNumber;
for(int i = number; i >= 0; i -= 2)
{
decreasedNumber = i;
//decreased number from the outer loop will decrease once again
for(int j = decreasedNumber; decreasedNumber >= 0; decreasedNumber -=2)
{
cout << decreasedNumber << " ";
}
cout << endl;
}
}
int main()
{
//Prompting the user to enter a number and collect that input
cout << "Enter a number: " << endl;
cin >> number;
cout << row(number);
return 0;
}