# Puzzling problem

• 01-27-2010
bijan311
Puzzling problem
Code:

```#include <iostream> #include <cmath> using namespace std; void math() {         char line;         float number;         float answer;         char yn = 'y';         do{   cout<<"enter what you want to do (m for math, o for math operations, s for square root, f for farenheit to celsius, c for celsius to farenheit)\n";   cin>>line;   if(line == 'o'){           cout<<"x,/,+,-,^,s(press enter then enter the number)\n";           answer = 0;   }   if(line == 's'){           cout<<"enter a number: ";           cin>>number;           answer = sqrt(number);   } if(line == 'm'){                 float x;         float y;         char a;                 float answer;                 cout<<"enter a problem\n";           cin>>x>>a>>y;     switch (a){         case 'x':                 answer = x*y;                 break;         case '/':                 answer = x/y;                 break;         case '+':                 answer = x+y;                 break;         case '-':                 answer = x-y;                 break;         case '^':                 answer = pow (x,y);                 break; } }   if(line == 'c'){           float degrees;           cout<<"enter degrees celsius\n";           cin>> degrees;           answer = 1.8*degrees+32;   }   if(line == 'f'){           float degrees;           cout<<"enter degrees farenheit\n";           cin>> degrees;           answer = (degrees-32)*1.8;   }   cout<<answer<<endl;   cout<<"Do you want to calculate something else<y/n>\n";   cin>>yn;         }while(yn == 'y'); }```
Code:

```#include <iostream> #include "calc.h" using namespace std; int main() {         math(); }```
my problem is when you do an equation (x,/,+,-,^) it gives you an error or the previous number, and this only happens when you press m at the beginning, no where else.
• 01-27-2010
cs_student
After the conditional to check for the 'm' char, you re-declare the "answer" variable.
• 01-28-2010
bijan311
thanks