# Thread: Newbie needs a bit of help

1. ## Newbie needs a bit of help

I'm new to coding and I know the code isn't fully functional but bare with me and help me deal with the problem at hand, thanks!

Code:
```#include <iostream>
using namespace std;

void numcheck();
int subtract(int,int);
int divide(int,int);
int multiply(int,int);

void main()
{
int input;
int num1,num2;

cout << "Pick your Method: " << endl;
cout << "1)Add\n" << "2)Subtract\n" << "3)Divide\n" << "4)Multiple" << endl;

cin >> input;

switch (input)
{
case 1://subtract
numcheck();
cin >> num1,num2;
int s;
s = subtract(num1,num2);
cout << s << endl;
break;
case 2://divide
numcheck();
cin >> num1,num2;
int d;
d = divide(num1,num2);
cout << d << endl;
break;
case 3://multiply
numcheck();
cin >> num1,num2;
int m;
m = multiply(num1,num2);
cout << m << endl;
}
}

void numcheck()
{
cout << "Enter two numbers for the Equation"<< endl;
}

{
}

int subtract(int a,int b)
{
int subtract;
subtract = a-b;
return(subtract);
}

int divide(int a, int b)
{
int divide;
divide = a/b;
return(divide);
}

int multiply(int a,int b)
{
int multiply;
multiply = a*b;
return(multiply);
}```
Error:
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(29) : warning C4700: uninitialized local variable 'num2' used

2. Code:
`cin >> num1,num2;`
Should be

Code:
`cin >> num1  >> num2;`
Also, and this is just informational more than anything.

Code:
```int add(int a, int b)
{
return a+b;
}```
Works too. Also, you shouldn't name variables the same name as the function. I am surprised that even compiled without mentioning that fact to you.

3. yea i was surprised too, maybe microsoft allows you to do this

4. Well its interesting trivia to know. That doesn't mean you should do it.

5. It compiles because you're using the comma operator which says, basically, evaluate the left, then the right, and have the whole expression take on the value of the right operand.

It's like saying
Code:
```cin >> a;
b;```
(because you're not using the value of the expression). And, of course, a statement like "b;" does absolutely nothing.

Code:
```\$ cat shiftcomma.cpp
#include <iostream>

int main() {
int a, b;
std::cin >> a, b;
return 0;
}
\$ g++ -W -Wall -ansi -pedantic -g shiftcomma.cpp -o shiftcommashiftcomma.cpp: In function ‘int main()’:
shiftcomma.cpp:5: warning: right-hand operand of comma has no effect
\$```

6. http://cpwiki.sf.net/void_main
Simply put, don't use it.

7. ok here is my updated program

Code:
```#include <iostream>
#include <cstdlib>
using namespace std;

void numcheck();
int subtract(int,int);
int divide(int,int);
int multiply(int,int);
void selection_case();

void main()
{

int restart;

cout << "Pick your Method: " << endl;
cout << "1)Subtract\n" << "2)Divide\n" << "3)Multiple\n" << "4)Add" << endl;

selection_case();

cout << "Make Another Selection(Press R): " << endl;

cin >> restart;

if (restart = 'r')
{
system("CLS");
selection_case();
}
else
{
cout <<	"Thanks" << endl;
exit(1);
}

}

void numcheck()
{
cout << "Enter two numbers for the Equation"<< endl;
}

{
return a+b;
}

int subtract(int a,int b)
{
return a-b;
}

int divide(int a, int b)
{
return a/b;
}

int multiply(int a,int b)
{
return a*b;
}

void selection_case()
{

int num1,num2;
int input;
cin >> input;

switch (input)
{
case 1://subtract
numcheck();
cin >> num1 >> num2;
int s;
s = subtract(num1,num2);
cout << s << endl;
break;
case 2://divide
numcheck();
cin >> num1 >> num2;
int d;
d = divide(num1,num2);
cout << d << endl;
break;
case 3://multiply
numcheck();
cin >> num1 >> num2;
int m;
m = multiply(num1,num2);
cout << m << endl;
numcheck();
cin >> num1 >> num2;
int a;
cout << a << endl;
}
}```
my code now has a little bit of function. the problem I've run into is not exactly an error. In bold, is where I believe I'm having trouble. When I get to this point I am suppose to type in r if I want to clear the screen and ask the question again. I do this but it just gives me the end of program "press any button to continue". I'm thinking it may have something to do with getchar(); , but Im not too sure.

8. Code:
`	if (restart = 'r')`
should be
Code:
`	if (restart == 'r')`

9. And how do you expect cin to read 'r' into an int?

10. Get rid of void main.

11. char restart