|
-
Nov 17th, 2002, 09:33 PM
#1
Thread Starter
New Member
[resolved]
Code:
#include <iostream.h>
typedef short int si;
int main()
{
si theShoe = 20;
si theTie, theWatch;
cout << "enter the price for your watch\n";
cin >> theTie;
cout << "Enter a price for your tie\n";
cin >> theWatch;
{
if ( (theTie >= theWatch) && ( (theTie + theWatch) > theShoe) )
cout << "the shoe is less then the watch and the tie combined\n";
else
if ( (theTie == theWatch) || ((theTie + 10) == theWatch) )
cout << "the tie is either worth as much as the watch or the tie is 10$ more then the then watch\n";
return 0;
}
}
Ok when it asks for me to type in the price of the tie and watch if I type in 11 then it will print the shoe is less then the watch... but if I type in something else wher eit makes the statement true it will not print the shoe is less then the watch.
Can anyone tell me what I have done wrong or something I can do to fix it please
Thanks,
Bb
Last edited by Bebo; Nov 17th, 2002 at 11:41 PM.
-
Nov 17th, 2002, 09:49 PM
#2
transcendental analytic
cout << "enter the price for your watch\n";
cin >> theTie;
cout << "Enter a price for your tie\n";
cin >> theWatch;
shouldn't it be the other way around?
cout << "the tie is either worth as much as the watch or the tie is 10$ more then the then watc
|| is or/and in english, in this case its not possible to have and, but exclusive or("either or" in english) is ^ in C++, nothing wrong, just so you know the difference
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 17th, 2002, 09:56 PM
#3
Thread Starter
New Member
lol, I didnt put much thought in what it said. Just trying to get the program to do what I want
-
Nov 17th, 2002, 11:40 PM
#4
Thread Starter
New Member
o wait nvm I see what your saying :\
-
Nov 17th, 2002, 11:44 PM
#5
Thread Starter
New Member
Code:
#include <iostream.h>
typedef short int si;
int main()
{
si theShoe = 20;
si theTie, theWatch;
cout << "enter the price for your watch\n";
cin >> theWatch;
cout << "Enter a price for your tie\n";
cin >> theTie;
{
if ( (theTie > theWatch) && ( (theTie + theWatch) > theShoe) )
cout << "the shoe is less then the watch and the tie combined\n";
else
if ( (theTie == theWatch) ^ ((theTie + 10) == theWatch) )
cout << "the tie is either worth as much as the watch or the tie is 10$ more then the then watch\n";
else
cout << "the watch is worth more then everything\n";
}
return 0;
}
Here is what I have now... I still wouldnt mind any suggestions 
thanks,
Bb
-
Nov 18th, 2002, 05:37 AM
#6
^ is only a bitwise operator! There is no logical XOR in C++!
You have to simulate it:
cond1 XOR cond2
can be written as
(cond1 AND NOT cond2) OR (NOT cond1 AND cond2)
in C++ syntax:
(cond1 && !cond2) || (!cond1 && cond2)
And it's
#include <iostream>
using namespace std;
not
#include <iostream.h>
which is deprecated!
You also don't need to write short int, you can just write short. Which makes the typedef unnecessary.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 18th, 2002, 05:41 AM
#7
But in your case you don't need XOR. Here are the truth tables of OR and XOR:
Code:
OR 0 1 XOR 0 1
0 0 1 0 0 1
1 1 1 1 1 0
Since it is logically impossible that the watch has the same price as the tie AND has a price exactly 10 higher than the tie you can remove the lower right field from the table wich leaves you with two identical tables. So you can use the simple OR here.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|