I have to make a calculator implementing a stack to save files from the anwsers of each operation and then pop them out if the operation continues. The calc takes the data on this format: 1 3 + 2 * 4 /
The operation should give back a result of 2, and as you can see its a weird way to imput the operations but yeah thats what my teacher wants.
Here is what i have so far:
#include <iostream>
using namespace std;
struct Nodo{
float val;
Nodo *sig;
};
Nodo *pinicio=NULL;
void ppush(float x){
Nodo *temp;
temp=new Nodo;
temp->val=x;
temp->sig=NULL;
if(pinicio!=NULL)
temp->sig=pinicio;
pinicio=temp;
}
float ppop(){
Nodo *temp;
temp=pinicio;
float y=temp->val;
pinicio=pinicio->sig;
delete temp;
return y;
}
int main(){
char op[50];
char temp[8];
int i=0,j=0;
float y=0.f;
float tmp=0.f;
float res=0.f;
float val1=0.f;
cout<<"Imput the operation ";
gets(op);
do{
while(op[i]!= ' '){
temp[j]=op[i];
i++;
j++;
}
if(temp[j]=='+'){
y=ppop();
val1=ppop();
res=val1+y;
}
if(temp[j]=='-'){
}
if(temp[j]=='*'){
}
if(temp[j]=='/'){
}
if(temp[j]!='+'||temp[j]!='-'||temp[j]!='*'||temp[j]!='/'||temp[j]!=' ')
tmp=atof(temp);
ppush(tmp);
temp[j]='\0';
j=0;
i++;
}while(res!=4);//this is 4 because for testing im imputing 1 3 +
cout<<endl;
cout<<res;
system("pause");
return 0;
}
As you can see im really lost so a good idea or a redirection would be very helpfull
Thank you

New Topic/Question
Reply




MultiQuote





|