I am incredibly new to programming and this is my first attempting at doing anything. I believe I had declared everything properly as well as the if statements, however I get multiple compilation errors that do not make any sense, as I cannot parse what they are trying to say is wrong with the code. I am incredibly confused and I want to learn what I am doing wrong.
Here is a list:
1. main.cpp: In function ‘int main()’:
main.cpp:28:19: error: expected primary-expression before ‘answer’
cin >> string answer;
^
2. main.cpp:30:19: error: ‘add’ was not declared in this scope
if (answer == add)
^
3. main.cpp:31:13: error: redeclaration of ‘int add’
int add(answer1,answer2);
^
4. main.cpp:30:19: note: ‘add’ previously declared here
if (answer == add)
^
5. main.cpp:31:13: error: ‘answer1’ was not declared in this scope
int add(answer1,answer2);
^
6. main.cpp:31:21: error: ‘answer2’ was not declared in this scope
int add(answer1,answer2);
^
7. main.cpp:31:28: error: expression list treated as compound expression in initializer [-fpermissive]
int add(answer1,answer2);
^
8. main.cpp:33:5: error: ‘else’ without a previous ‘if’
else if (answer == subtract)
^
9. main.cpp:33:24: error: ‘subtract’ was not declared in this scope
else if (answer == subtract)
^
10. main.cpp:34:18: error: redeclaration of ‘int subtract’
int subtract(answer1,answer2);
^
11. main.cpp:33:24: note: ‘subtract’ previously declared here
else if (answer == subtract)
^
12. main.cpp:34:18: error: ‘answer1’ was not declared in this scope
int subtract(answer1,answer2);
^
13. main.cpp:34:26: error: ‘answer2’ was not declared in this scope
int subtract(answer1,answer2);
^
14. main.cpp:34:33: error: expression list treated as compound expression in initializer [-fpermissive]
int subtract(answer1,answer2);
^
15. main.cpp:36:5: error: ‘else’ without a previous ‘if’
else if (answer == multiply)
^
16. main.cpp:36:24: error: ‘multiply’ was not declared in this scope
else if (answer == multiply)
^
17. main.cpp:37:18: error: redeclaration of ‘int multiply’
int multiply(answer1,answer2);
^
18. main.cpp:36:24: note: ‘multiply’ previously declared here
else if (answer == multiply)
^
19. main.cpp:37:18: error: ‘answer1’ was not declared in this scope
int multiply(answer1,answer2);
^
20. main.cpp:37:26: error: ‘answer2’ was not declared in this scope
int multiply(answer1,answer2);
^
21. main.cpp:37:33: error: expression list treated as compound expression in initializer [-fpermissive]
int multiply(answer1,answer2);
^
22. main.cpp:39:5: error: ‘else’ without a previous ‘if’
else if (answer == divide)
^
23. main.cpp:39:24: error: ‘divide’ was not declared in this scope
else if (answer == divide)
^
24. main.cpp:40:16: error: redeclaration of ‘int divide’
int divide(answer1,answer2);
^
25. main.cpp:39:24: note: ‘divide’ previously declared here
else if (answer == divide)
^
26. main.cpp:40:16: error: ‘answer1’ was not declared in this scope
int divide(answer1,answer2);
^
27. main.cpp:40:24: error: ‘answer2’ was not declared in this scope
int divide(answer1,answer2);
^
28. main.cpp:40:31: error: expression list treated as compound expression in initializer [-fpermissive]
int divide(answer1,answer2);
^
29. main.cpp:42:5: error: ‘else’ without a previous ‘if’
else if
^
30. main.cpp:43:5: error: expected ‘(’ before ‘cout’
cout << "Invalid Option!";
^
31. main.cpp: At global scope:
32. main.cpp:50:14: error: ‘a’ was not declared in this scope
int subtract(a,b);
^
33. main.cpp:50:16: error: ‘b’ was not declared in this scope
int subtract(a,b);
^
34. main.cpp:50:17: error: expression list treated as compound expression in initializer [-fpermissive]
int subtract(a,b);
^
35. main.cpp:51:1: error: expected unqualified-id before ‘{’ token
{
^
36. main.cpp:56:14: error: ‘a’ was not declared in this scope
int multiply(a,b);
^
37. main.cpp:56:16: error: ‘b’ was not declared in this scope
int multiply(a,b);
^
38. main.cpp:56:17: error: expression list treated as compound expression in initializer [-fpermissive]
int multiply(a,b);
^
39. main.cpp:57:1: error: expected unqualified-id before ‘{’ token
{
^
40. main.cpp:62:9: error: ‘a’ was not declared in this scope
int add(a,b);
^
41. main.cpp:62:11: error: ‘b’ was not declared in this scope
int add(a,b);
^
42. main.cpp:62:12: error: expression list treated as compound expression in initializer [-fpermissive]
int add(a,b);
^
43. main.cpp:63:1: error: expected unqualified-id before ‘{’ token
{
^
44. main.cpp:68:12: error: ‘a’ was not declared in this scope
int divide(a,b);
^
45. main.cpp:68:14: error: ‘b’ was not declared in this scope
int divide(a,b);
^
46. main.cpp:68:15: error: expression list treated as compound expression in initializer [-fpermissive]
int divide(a,b);
^
47. main.cpp:69:1: error: expected unqualified-id before ‘{’ token
{
^
Here is the code:
#include <iostream>
using namespace std;
int main()
{
int number1;
int number2;
string answer;
int result;
int a;
int b;
cout << "Enter first number" << endl;
cin >> number1;
cout << "Enter second number" << endl;
cin >> number2;
cout << "What would you like to do?" << endl << "Options: Add, substract,
multiply, divide" << endl;
cin >> string answer;
if (answer == add)
int add(answer1,answer2);
cout << result;
else if (answer == subtract)
int subtract(answer1,answer2);
cout << result;
else if (answer == multiply)
int multiply(answer1,answer2);
cout << result;
else if (answer == divide)
int divide(answer1,answer2);
cout << result;
else if
cout << "Invalid Option!";
return 0;
}
int subtract(a,b);
{
result = a-b;
return result;
}
int multiply(a,b);
{
cout << a*b;
}
int add(a,b);
{
cout << a+b;
}
int divide(a,b);
{
cout << a/b;
}