Vcoderz Community
We create websites that have it all, beauty & brains
Lebanon Web Design & Development - Coddict
 

Go Back   Vcoderz Community > Computer Zone > Computers & Information Technologies > E-Learning Center

Notices

E-Learning Center E-Learning tutorials and competitions.

Reply
 
Share Thread Tools Search this Thread
Old 12-03-2008   #1
sciencedoor
Registered Member
 
sciencedoor's Avatar
 
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
Default c++ guru, urgent plz

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
sciencedoor is offline   Reply With Quote
Old 12-03-2008   #2
sciencedoor
Registered Member
 
sciencedoor's Avatar
 
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
Default Re: c++ guru, urgent plz

ex3 solved
first 1 plz
__________________
Chase two birds at the same time and you will loose both
sciencedoor is offline   Reply With Quote
Old 12-03-2008   #3
Sheriff Ice
info@sync.com.lb
 
Sheriff Ice's Avatar
 
Last Online: 2 Weeks Ago
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
Default Re: c++ guru, urgent plz

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";
something similar to this

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
Sheriff Ice is offline   Reply With Quote
The Following User Says Thank You to Sheriff Ice For This Useful Post:
sciencedoor (12-03-2008)
Old 12-03-2008   #4
sciencedoor
Registered Member
 
sciencedoor's Avatar
 
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
Default Re: c++ guru, urgent plz

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
sciencedoor is offline   Reply With Quote
Old 12-03-2008   #5
Tawa
 
Tawa's Avatar
 
Last Online: 04-23-2018
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,120
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
Default Re: c++ guru, urgent plz

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;
This Should Do The Work.
__________________
What we do in life, echoes in eternity.
Tawa is offline   Reply With Quote
The Following User Says Thank You to Tawa For This Useful Post:
sciencedoor (12-03-2008)
Old 12-05-2008   #6
Malek
Registered Member
Tetris Champion
 
Malek's Avatar
 
Last Online: 11-04-2014
Join Date: Sep 2006
Posts: 1,302
Thanks: 102
Thanked 1,147 Times in 619 Posts
Groans: 8
Groaned at 1 Time in 1 Post
Default Re: c++ guru, urgent plz

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;
}
Malek is offline   Reply With Quote
Reply

  Vcoderz Community > Computer Zone > Computers & Information Technologies > E-Learning Center

Tags
guru, plz, urgent



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:50 AM.


Lebanon web design and development
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Share