+ 1
How to create my own functions?
I am not quite to the tutorial where it discusses functions, but I am working on a project right now that I really want to create a function for. I am trying out this code: #include <iostream> using namespace std; int main() { int mathQuestion(int q){ if (q == 1){ cout<<"1. What is 1+1?"<<endl; cin>>a; cout<<"Your answer: "<<a<<endl; if (a==2){ cout<<"Correct!"<<endl; k+=1; } else{ cout<<"Incorrect"<<endl; } } } mathQuestion(1); return 0; } My compiler gives me two errors: 1. a function-definition is not allowed here before '{' token "int mathQuestion (int q){" 2. expected '}' at end of input (very last line
1 Answer