So...this is my first time messing around with functions and almost never worked with for
either and I wanted to create a function that printed hello as many times as the parameter (n
) said.
#include <iostream>
int say_hello(int n){
for(int n, int t=0; t!=n; t++){
std::cout << "Hello" << std::endl;
}
}
int main(){
say_hello(5);
return 0;
}
But I seem to have done something horribly wrong because of all these errors.
- error: expected unqualified-id before 'int'
- error: expected ';' before 'int'
- warning: for increment expression has no effect [-Wunused-value]
- error: expected ')' before ';' token
- error: 't' was not declared in this scope
- error: expected ';' before ')' token
- warning: no return statement in function returning non-void [-Wreturn-type]
I want to learn C++ properly and at least try to not get into too many bad habits, any advice on sites or beginner challenges?