473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

rpn calculator

i ve done so far this code but it deals only with 1 digit numbers i dont know how to make it work for 2 or more digited no.s using atoi or atof functions

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
char postfix[100];
int stack[100];
int top=-1;
void push(int x)
{
top++;
stack[top]=x;
}
int pop()
{
return stack[top--];
}
int evalpost()
{
int a,b,i,temp,result,len;
len=strlen(postfix);
for(i=0;i<len;i++)
{
if(postfix[i]<='50'&&postfix[i]>='0')
push(postfix[i]-'0');
else
{
a=pop();
b=pop();
switch(postfix[i])
{
case'+':
temp=a+b;break;
case'-':
temp=b-a;break;
case'*':
temp=a*b;break;
case'/':
temp=b/a;break;
}
push(temp);
}
}
result=pop();
return result;
}
void main()
{
printf("enter rpn\n");
gets(postfix);
top=-1;
int x=evalpost();
printf("%d\n",x);
}




and thanks for ur concern
May 1 '10 #1
1 3529
whodgson
542 512MB
Do you mean revs/nautical_mile..........and please put your code in between code tags which makes it much easier to read.
See what you can make of the following:
Expand|Select|Wrap|Line Numbers
  1. cout<<"\ndemonstrating the atoi()function\n";
  2.  
  3.     const char* s="  21xy 3";
  4.     const char*s1= " 74.7xyz ";
  5.     cout<<"the first string is \n"<<s<<endl;
  6.     cout<<"the second string is \n"<<s1<<endl;
  7.     n=atoi(s);
  8.     m=atoi(s1);
  9.     cout<<"after converting strings to integers ";
  10.     cout<<"s= "<<n<<" and s1="<<m<<endl;
  11.     cout<<"the product of s and s1 is "<<n*m<<endl; 
  12.  
  13.  
  14. char q;
  15. cout<<"press any key to continue...";
  16. cin.get(q);
  17. return 0;    
  18.  
  19. }    
  20. /*
  21. demonstrating the atoi()function
  22. the first string is
  23.   21xy 3
  24. the second string is
  25.  74.7xyz
  26. after converting strings to integers s= 21 and s1=74
  27. the product of s and s1 is 1554
  28. press any key to continue...*/
  29.  
May 2 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
3
by: Art | last post by:
Hi, In part of my application the user may need to do a simple arithmetic calculation in order to get the value to put in a text box. I was thinking that it would be good if I could display the...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
5
Deathwing
by: Deathwing | last post by:
Hi everyone one I'm playing around with trying to make an expense calculator. I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.