Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,262 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,499 people online right now. Registration is fast and FREE... Join Now!




evaluating expressions

 
Reply to this topicStart new topic

evaluating expressions, please explian what is being asked

jona431
14 Oct, 2006 - 07:59 PM
Post #1

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
I,m not sure what is being asked of me here. I have posted below what information is being asked, and the code I think that it is asking for. If anyone knows please explain if I am off track. Thanks in advance

Given: int a = 4, b = 5, c = 7, x = 12;
Evaluate each expression:

a) _________________ c / b = = 2

cool.gif __________________ c % b = = 2

c) __________________ b = c / a != c – a

d) __________________ (b < c) && (c = = 7)

e) __________________ (c + x – b == 0) || (a = 5)


CODE

#include <stdio.h>
#include <conio.h>

int main()
{
    int a=4, b=5, c=7, x=12;
    int Answer=0;

    Answer=c/b==2;
        printf("The Answer for question a is:%i ",Answer);

    
    getch ();

return 0;
}

User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Evaluating Expressions
14 Oct, 2006 - 08:08 PM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
what did you get for your first answer?
User is offlineProfile CardPM
+Quote Post

jona431
RE: Evaluating Expressions
14 Oct, 2006 - 08:16 PM
Post #3

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
My 1st answer was 1, then I made a change now I'm getting 0
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Evaluating Expressions
14 Oct, 2006 - 09:04 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Hmm...unless there are other instructions to your problem these are simple True/False questions. You are being asked to evaluate each expression to determine whether it is a True statement or a False statement.

You do that by substituting the numbers provided for each variable:
For example:
int a = 4, b = 5, c = 7, x = 12;

The first problem is c / b = = 2, simply substitue the numbers 7 / 5 = 1.4. And so the problem resolves to 1.4 == 2. Now is this in its current form a true statement? Does 1.4 equal 2?

The answer is either true 1.4 does equal 2 or else the answer is false 1.4 does not equal 2.

Now apply that same logic to the rest of the problems.
User is offlineProfile CardPM
+Quote Post

jona431
RE: Evaluating Expressions
14 Oct, 2006 - 09:15 PM
Post #5

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
Thanks jayman9, that helps alot. smile.gif
User is offlineProfile CardPM
+Quote Post

jona431
RE: Evaluating Expressions
16 Oct, 2006 - 12:46 PM
Post #6

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
I'm not sure how I need to write this??? Should it be in a switch with several cases??..Any more help is appreciated!
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Evaluating Expressions
16 Oct, 2006 - 03:07 PM
Post #7

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Well, a switch statement would imply that you are making a decision based on some input...which does not appear to be the case. I expect you could simply proceed along the lines you're going...

CODE

int main(void)
{
   int a=4, b=5, c=7, x=12;
   printf("The Answer for question a is:%i ",(c/b==2));
   return 0;
}

and so on...or assign the results to a variable as you've done in the first example and print.

Was it specified that you actually had to write code for these evaluations?

If so, perhaps the most intuitive way to proceed might be to use an if else construct for each:
CODE

int main(void)
{
   int a=4, b=5, c=7, x=12;
   if(c/b==2)
      printf("True");
   else
      printf("False");
   return 0;
}

And so on.
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Evaluating Expressions
16 Oct, 2006 - 05:18 PM
Post #8

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
it's just a simple boolean statement and displaying the result if you want.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:03PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month