473,398 Members | 2,212 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,398 software developers and data experts.

can someone help me make an int main() program

I've gotten help writing out these functions, and i know what they each do individually, but i can't figure out where to start in my main program, i want to enter a string of numbers and operators(+,-,*,/) and have the output be the answer(ex. 12+3- would be (1+2)-3=0, im almost certain my functions are fine, they compile without error, any help would be appreciated



Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. #define MAX_LENGTH 80
  6. int top_operator=0;
  7. char stack_operator[MAX_LENGTH];
  8. int array_pt=0;
  9. char array[MAX_LENGTH];
  10. unsigned int top_operand=0;
  11. float stack_operand[MAX_LENGTH];
  12.  
  13. // Some code has been removed as per FAQ policy
  14.  
  15. int main()
  16. {
  17.    return 0;
  18. }
Mar 6 '07 #1
5 1610
Ganon11
3,652 Expert 2GB
You'll have to get user input - probably character-by-character - and separate it into numbers, operators, etc. From there, you can use your functions depending on what input you get.

You should write (or find) functions that will determine if a character is a number, and a function that will determine if a character is an operator.
Mar 6 '07 #2
hi, i'm almost certain all of these functions are correct and will do what I want them to do, however, i am having trouble with the main program and am having trouble making the functions interact with one another......what i want to do is, be able to enter a string(ex. 1+2*3) and have the output be(7). any help would be appreciated!


Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. #define MAX_LENGTH 80
  6. int top_operator=0;
  7. char stack_operator[MAX_LENGTH];
  8. int array_pt=0;
  9. char array[MAX_LENGTH];
  10. unsigned int top_operand=0;
  11. float stack_operand[MAX_LENGTH];
  12.  
  13. //-------------------------------------------
  14.  
  15. <code snipped as per posting guidelines>
  16.  
  17. void infixTopostfix(char *str)
  18. {
  19.     char *input_string=str;
  20.     char ch;
  21.  
  22.  
  23.     push('(');
  24.     strcat(input_string, ")");
  25.  
  26.     while(*input_string)
  27.     {
  28.         switch(*input_string)
  29.         {
  30.         case '+':
  31.         case '-':
  32.         case '*':
  33.         case '/':
  34.             while(1)
  35.             {
  36.                 char top_char=top();
  37.                 if(top_char=='\0')
  38.                 {
  39.                     cout<<"Invalid expression"<<endl;
  40.                     exit(0);
  41.                 }
  42.                 else
  43.                 if (isOperator(top_char))
  44.     {
  45.     if(precedence_level(top_char)>=precedence_level(*input_string))
  46.         array[array_pt++]=pop();
  47.             else
  48.             break;
  49.     }
  50.     else 
  51.     break;
  52.             }
  53.         }
  54.     }
  55.     push(*input_string);
  56. }
  57. //----------------------------------------------------------------------------------
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. int _tmain(int argc, _TCHAR* argv[])
  65. {
  66. char token[10];
  67.  
  68. cout<<"Enter string"<<endl;
  69. cin>>token;
  70. infixTopostfix(token);
  71. evaluatePostfixExpr();
  72. cout<<evaluate();
  73.  
  74.  
  75.  
  76.  
  77.     return 0;
  78. }
  79.  
Mar 6 '07 #3
lqdeffx
39
just to help everyone out don't forget to put code inside code tags.

Expand|Select|Wrap|Line Numbers
  1. <snipped>
  2.  
Mar 6 '07 #4
what exactly is the problem?

This is what I can give you:

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char* argv[])
  2. {
  3.     char token[10];
  4.  
  5.     cout<<"Enter string"<<endl;
  6.     cin>>token;
  7.     infixTopostfix(token);
  8.     evaluatePostfixExpr();
  9.     cout<<evaluate();
  10.     return 0;
  11. }
  12.  
Don't forget the code tags, you're just annoying everyone if you forget
Mar 6 '07 #5
Banfa
9,065 Expert Mod 8TB
Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

So far you have posted your full code twice forcing us to edit it twice and double posted your question.

Please post within the posting guidelines.


I do not believe that you do know what each of your functions individually do, specifically I do not believe that you know what infixTopostfix does or you would not attempt to call it in the way you have. Passing "1+2*3" to infixTopostfix causes the program to enter an infinite loop which is what you suggest you do from your text and the way you have written main.

However I know you haven't actually tried your program and examined the output or what it does when it runs because the code you posted does not even compile.

If you understand each function then it should not be a great leap to working out how to call them, so I suggest to clue us in on how you think each function works at which point we may be able to explain to you the part you are mis-understanding.

Banfa
Administrator
Mar 7 '07 #6

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

Similar topics

0
by: blockhead | last post by:
We are looking for someone to either complete a php forum program or create one for us. There isn't really anything that is available that suits our needs and we have specific wants. If you are...
23
by: Tiny Tim | last post by:
I am new C program student. I wonder can we write a program in C that just trigger its function to do a certain action ? In this case, I have a program but it is not working. What I want is for...
2
by: shblack | last post by:
Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues...
8
by: Joshua Moore | last post by:
/* Hi, I was hoping someone could help me with this problem. I did my work and worked my way through the usual compiler messages, but I have run against some problem I can't identify. The compiler...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
40
by: aslamhenry | last post by:
please key in any 5 digits number : 56789 and the ouput is 5678 9 567 89 56 789 5 6789
13
by: carlos123 | last post by:
ok the following code , is the code for my program, basicly, i use bluej, so i can just copy and paste some code into the forums and someone else can copy it in to their editor, so basicly i want...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.