Vcoderz Community

Vcoderz Community (http://forum.vcoderz.com/index.php)
-   E-Learning Center (http://forum.vcoderz.com/forumdisplay.php?f=33)
-   -   c++ guru, urgent plz (http://forum.vcoderz.com/showthread.php?t=14094)

sciencedoor 12-03-2008 08:13 AM

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

sciencedoor 12-03-2008 09:07 AM

Re: c++ guru, urgent plz
 
ex3 solved
first 1 plz

Sheriff Ice 12-03-2008 09:53 AM

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

sciencedoor 12-03-2008 10:10 AM

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

Tawa 12-03-2008 10:36 AM

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.

Malek 12-05-2008 12:13 AM

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;
}



All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger