What's wrong with my switch function?
Hi,
I am very new to C++... in fact I started last night at 10:00. I started so I can make a extra credit function for math (if anyone wants to help me out with that, email me). Anyways, I am having alot of fun, but I can't seem to get "switch" statements to work. Whenever I input the selection of the case I want to run, the window crashes.
Here's my source code of a simple program I was trying to write:
Code:
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
int selection;
cout<<"Please enter 2 numbers: ";
cin>> x >> y;
cin.ignore();
cout<<"What would you like to do with these numbers:\n";
cout<<"1. Add them\n";
cout<<"2. Subtract them\n";
cout<<"Selection: ";
cin>> selection;
switch (selection) {
case 1:
return x + y;
break;
case 2:
return x - y;
break;
default:
cout<<"Error\n";
break;
}
cin.get();
}
I got a simpler switch statement to work, but whenever I try more advanced stuff, it crashes. Can someone help me? Am I missing a measly equal sign or period somewhere?
Thanks!
P.S. I'm using Dev-C++ 5