May 16th, 2011, 12:41 AM
#1
Beginners question about methods
Hi all! I am just taking my first steps into learning c++ for fun, but I can't seem to get some code working here...
a simple method I am using returns the error:
error C2601: 'Addition' : local function definitions are illegal
1> getline.cpp(11): this line contains a '{' which has not yet been matched
it seems to be refering to :
int Addition(int x, int y){
int useranswer;
useranswer = x + y;
return useranswer;
}
and as far as I can see the { is matched with } at the end, is it not?
can anyone help me with this, please?
the entire (unfinished) code is:
#include <iostream>
#include "conio.h"
#include <string>
using namespace std;
int Addition(int x, int y);
int Subtraction(int x, int y);
int Multiplication(int x, int y);
void main(){
int num1;
int num2;
string mathtype;
cout << "What do you want to do? add, subtract, or multiply? ";
getline(cin, mathtype);
cin.clear ();
cout << "You picked " << mathtype << endl;
cout << "Enter a number: ";
cin >> num1;
cout << "Enter another number: ";
cin >> num2;
if(mathtype == "add"){
cout << "The numbers added equal " << Addition(num1, num2) << endl;
}
int Addition(int x, int y){
int useranswer;
useranswer = x + y;
return useranswer;
}
I have tried adding the other Subtraction and Multiplication methods, but they don't work either. Where am I missing the }?
Thanks in advance!
Attached Images
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width