|
|
|||||||
| E-Learning Center « E-Learning tutorials and competitions. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Registered Member
Last Online: 10-12-2012
Join Date: Nov 2006
Posts: 314
Thanks: 85
Thanked 167 Times in 81 Posts
Groans: 2
Groaned at 0 Times in 0 Posts
|
ex1:
Using a do while loop , write a calculator program that reads an arithmetic such as 12+34-2+65-21= from the user and gives you the result when it reads the equal sign.The expression can contain any number of integers and not just five as in the above example .The only arithmetic operators used are +,-,and = . (no strings, no arrays..) that's what they want for suggestion comments send ok ex3: input an integer containing only 0s and 1s (i.e a binary integer )and print its decimal equivalent plz cuz i dont have time to search
__________________
Chase two birds at the same time and you will loose both
|
|
|
|
|
|
#2 |
|
Registered Member
Last Online: 10-12-2012
Join Date: Nov 2006
Posts: 314
Thanks: 85
Thanked 167 Times in 81 Posts
Groans: 2
Groaned at 0 Times in 0 Posts
|
ex3 solved
first 1 plz
__________________
Chase two birds at the same time and you will loose both
|
|
|
|
|
|
#3 |
|
info@sync.com.lb
Last Online: 11-29-2020
Join Date: Apr 2006
Posts: 3,827
Thanks: 1,348
Thanked 2,391 Times in 1,306 Posts
Groans: 0
Groaned at 16 Times in 15 Posts
|
LOL man the first one is so easy
just create two integers x , y, one char z, and put two condition( if else condition for the char inputted by the user i mean the + , -) inside the "do while" loop, each time the user enters a number the loop add it or subtract it depending on the user request by selecting the sign he wants. similar to this Code:
if (z== '+') x+y= x; if (z== '-') x-y = x; if (z== '=') cout<<"the result of ur equation is "<< x<<endl; else cout<<"you entered an invalid value, plz retry"; the code that i wrote should be in the do while loop the do while loop should have a condition to exit from the loop ya3ne declare an integer and assign a value to it if a ==1 than exit you should know how to write such stuff refer to the book ur studyin PS: dont copy my code its full of mistakes, and it is just a sample not a working one, im trying to help you and give you a convention how ur program should be
__________________
http://www.gamync.com Lebanese Produced Mobiles Games by http://www.sync.com.lb |
|
|
|
| The Following User Says Thank You to Sheriff Ice For This Useful Post: | sciencedoor (12-03-2008) |
|
|
#4 |
|
Registered Member
Last Online: 10-12-2012
Join Date: Nov 2006
Posts: 314
Thanks: 85
Thanked 167 Times in 81 Posts
Groans: 2
Groaned at 0 Times in 0 Posts
|
ma 3a add mannou hayyin ma fakkarit fi
3melet el sa3been men ta7it wou taraktou ma ba3reef chou sar, freezing... 10Q
__________________
Chase two birds at the same time and you will loose both
|
|
|
|
|
|
#5 |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
Code:
int x, y;
char z;
cin >> x;
while(1){
cin >> z;
if(z != '+' && z != '-')
break;
cin >> y;
if(z == '+')
x+=y;
else if(z == '-')
x-=y;
}
if(z != '=')
cout << "Syntax Error" << endl;
else
cout << "The Result Is: " << x << endl;
__________________
What we do in life, echoes in eternity.
|
|
|
|
| The Following User Says Thank You to Tawa For This Useful Post: | sciencedoor (12-03-2008) |
|
|
#6 |
|
Registered Member
Last Online: 06-22-2023
Join Date: Sep 2006
Posts: 1,304
Thanks: 102
Thanked 1,147 Times in 619 Posts
Groans: 8
Groaned at 1 Time in 1 Post
|
I had this assignment last week, anyway here's the code.
Code:
#include <iostream>
using namespace std;
int main()
{
int number,answer;
char operators;
cout<<"Enter an arithmetic expression : ";
cin>>number;
answer=number;
do
{
cin>>operators;
if(operators!='=')
{
cin>>number;
if(operators=='+')
answer+=number;
if(operators=='-')
answer-=number;
}
}while(operators!='=');
cout<<"The answer is : "<<answer<<endl;
return 0;
}
|
|
|
|
![]() |
|
| Tags |
| guru, plz, urgent |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|