hi; ı have a pproject please help me
In this first project you have to build a non-scientific calculator. The user should give the instructions as a sequence ending with sentinel “=” and your program should calculate the result without considering the precedence of the operators. In addition to these, your calculator has to be able to store values into a single variable, (i.e. called A below), which will probably be used in another input.
The variable name must consist of a single letter. If the user enters a non-letter character, you must warn the user until a letter is entered.
You can assume that the input sequence will consist of operators (defined below), numbers and the variable that is defined by the user. You can also assume that the input contains a valid expression terminated by “=”. So, you do not need to do any input check for the sequence. There will be no space between operators and numbers.
You must read the numbers as characters and convert them to number equivalents. There can only be positive integers. The operators that must be used are:
+ (addition), - (subtraction), * (multiplication), / (division), ^ (power)
• +, -, * are self explanatory,
• / performs normal division, not integer division:
5/2 = 2.5
• and ^ means power:
3^2 = 9 (meaning 3*3)
2^4 = 16 (meaning 2*2*2*2)
Note that you must implement this power operation by yourselves. There is a function in “math.h” called “pow”, but you cannot use that function in your project.
SAMPLE RUN:
(Your program’s output is given in blue. User input is in red.)
>>Welcome to the non-scientific calculator.
>>Please enter the variable name to use in the calculations
>>&
>>You must enter a letter! Please re-enter the variable name:
>>A
>>Please enter the sequence:
>> 3+1*4+5/2=
>>Result = 10.5
>>What do you want to do now?
a)Store the result in a variable
b)Make another calculation
c)Quit the program
Choice>> a
>>The variable A with the value 10.5 is stored.
>>What do you want to do now?
a)Store the result in a variable
b)Make another calculation
c)Quit the program
Choice>> b
>>Please enter the sequence:
>>A+4*2-15=
>> Result = 14.0
>>What do you want to do now?
a)Store the result in a variable
b)Make another calculation
c)Quit the program
Choice>> b
>>Please enter the sequence:
>>A+2^2=
>> Result = 156.25
>>What do you want to do now?
a)Store the result in a variable
b)Make another calculation
c)Quit the program
Choice>> c
Thank you for using the calculator…
• As you can see from the sample run, the program has to be menu driven.
9 replies to this topic
#1
Posted 29 May 2010 - 08:52 AM
|
|
|
#2
Posted 29 May 2010 - 10:49 AM
So, what's your question?
#3
Posted 29 May 2010 - 10:58 AM
so my quastion is that the user will enter an input that an array of a sequance for example 3+2*5+5/2=
and ı must find result .....the sequance can be 4+5= or 5 +7+6+8+9*76-435= how it can be;;,,, please helpppp
and ı must find result .....the sequance can be 4+5= or 5 +7+6+8+9*76-435= how it can be;;,,, please helpppp
#4
Posted 29 May 2010 - 11:49 AM
You will need to accept the input either character by character or as a string, and then analyze the characters to determine what should be done with them.
You may want to start with thinking about what characters would be legal, then move on from there.
You may want to start with thinking about what characters would be legal, then move on from there.
#5
Posted 30 May 2010 - 03:01 AM
coulld you give some codes please
#6
Posted 30 May 2010 - 04:07 AM
I don't think someone will give...without your effort!
If you have tried it,give the code here even if it doesn't works well.
Warrior
If you have tried it,give the code here even if it doesn't works well.
Warrior
#7
Posted 30 May 2010 - 05:07 AM
Give some kind of code, and we can guide you. You know you have to accept the user's input, then process it. Make a stub function for the processing and make sure you can get input, draw the menu, etc.
#8
Posted 30 May 2010 - 06:36 AM
int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10.....;
char c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;
scanf("%d%c%d%c%d%c%d%c%d%c%d%c.......",,&a1,&c1,&a2,&c2,&a3,&c3,&a4,&c4,&a5,&c5,&a5,&c5,&a6,&c6.........);
op are c1 c2 c3....
numbers a1 a2 a3....
and ı need a method to calculate especially my program calcualte 5+5*5=50 it is wrong because firstly adds 5 to 5 then multiply but it must be 30 because it must first multiply 5 to 5 then adds 5
char c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;
scanf("%d%c%d%c%d%c%d%c%d%c%d%c.......",,&a1,&c1,&a2,&c2,&a3,&c3,&a4,&c4,&a5,&c5,&a5,&c5,&a6,&c6.........);
op are c1 c2 c3....
numbers a1 a2 a3....
and ı need a method to calculate especially my program calcualte 5+5*5=50 it is wrong because firstly adds 5 to 5 then multiply but it must be 30 because it must first multiply 5 to 5 then adds 5
#9
Posted 30 May 2010 - 06:38 AM
ı want you use atoi ...please help ı am ı student comp engineering in turkey and this is my first year in school
#10
Posted 30 May 2010 - 09:42 AM
Once you define a variable, your input won't work.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









