# Puzzling problem

• 01-27-2010
bijan311
Puzzling problem
Code:

#include <iostream>
#include <cmath>

using namespace std;

void math()
{
char line;
float number;
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";
}
if(line == 's'){
cout<<"enter a number: ";
cin>>number;
}
if(line == 'm'){
float x;
float y;
char a;
cout<<"enter a problem\n";
cin>>x>>a>>y;
switch (a){
case 'x':
break;
case '/':
break;
case '+':
break;
case '-':
break;
case '^':
break;
}
}
if(line == 'c'){
float degrees;

cout<<"enter degrees celsius\n";
cin>> degrees;
}
if(line == 'f'){
float degrees;

cout<<"enter degrees farenheit\n";
cin>> degrees;

}
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