I need to put use the stacks for floats instead of integers but I tried turning every thing from int to float but it did not work. Here is my code. Any help will be appreciated.
Code:#include <stdio.h> #include <iostream.h> #include <stdlib.h> class STACK { private: int S[100];//stack int Ssize;//stack size public: STACK();//constructor void push(int c);//push char onto stack int pop(); //remove char from the stack int size(); // returns the number of items on the stack bool full(); // true if stack is full }; STACK::STACK() { Ssize =0; } void STACK::push(int c) { if (Ssize != 100) S[Ssize++]=c; else cout<<"***Stack overflow-program terminated..."<<endl; } int STACK::pop() { return S[--Ssize]; } bool STACK::full() { if (Ssize==100) return true; else return false; } int STACK::size() { return Ssize; } void main(void) { int a,b,end; int i; char M[]="(((4+8)/4)*(9-7));"; STACK V,O; i=0; while (M[i]!=';') { if (M[i]==')') { b=V.pop(); a=V.pop(); switch (O.pop()) { case 0: V.push(a+b); break; case 1: V.push(a-b); break; case 2: V.push(a*b); break; case 3: V.push(a/b); break; } } else switch(M[i]) { case'0': V.push(0); break; case'1': V.push(1); break; case'2': V.push(2); break; case'3': V.push(3); break; case'4': V.push(4); break; case'5': V.push(5); break; case'6': V.push(5); break; case'7': V.push(7); break; case'8': V.push(8); break; case'9': V.push(9); break; case'+': O.push(0); break; case'-': O.push(1); break; case'*': O.push(2); break; case'/': O.push(3); break; } i++; } cout<<V.pop()<<endl; cin>>end; return 0; }