0

firstly id like to thank people for helping me with my earlier problems.
anyway, for this program im working on, i want the user to be able to select between two patterns.

eg. pattern1 makes x=1 and y=0
pattern2 makes x=0 and y=0
i tried using if statements, but it doesnt seem to work properly.

here is my code - although i wont put all of it in

cout << "please select which pattern: ";
    cin >> pattern;   
    
    if  ( pattern == '1' )
        {
            target1 = 1;
            target2 = 0;
             
        }
    
    if  ( pattern == '2' )
        {
            target1 = 0;
            target2 = 1;
             
        }
    
    cout << endl << "target 1 is: " << target1 
    << endl << "target 2 is: " << target2;

the cout commands for the targets dont show up as i would expect. there is other stuff later on that needs to be selected and done so the else command wouldnt really work.

thanks

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by Narue
0

It seems to work fine for me. Can you be more specific about how it's not working properly? Perhaps also tell us what the type of your pattern variable is?

0

this is a screen dump

please select which pattern: 1

target 1 is: -1.#QNAN
target 2 is: 9.79083e+027
please select each pixel in the pattern:
pixel1:


as u can see the targets dont come up as what ive set, which is a bit crap, unless im putting the numerical value in wrong. i could attach my whole code but it is very long coz im not really started making it neat and having shortcuts.

0

I'm guessing that pattern isn't defined like this:

char pattern;

If that's the case, then you should probably be comparing pattern against 1 and 2 rather than '1' and '2':

if ( pattern == 1 )
{
  target1 = 1;
  target2 = 0;
}
    
if ( pattern == 2 )
{
  target1 = 0;
  target2 = 1;
}
0

Try the else statement. I dont know but i get the correct answers when i made a few adjustments in the code.

cout << "please select which pattern: ";
    cin >> pattern;   
    
    if  ( pattern == '1' )
        {
            target1 = 1;
            target2 = 0;
             
        }
    
   else ( pattern == '2' );
          {
            target1 = 0;
            target2 = 1;
             
        }
    
    cout << endl << "target 1 is: " << target1 ;
    cout << endl << "target 2 is: " << target2;

Added:
I used target1 and target2 as integers.

0

oh god, that was soo trivial, i should have known better, god this is a little frustrating. anyway thanks again for ur help. no doubt ull here from me soon

0

it wont allow me to use ( target1 - OUTC ) as a function, why would that be?

0

That's a very random question. You'll need to provide a context, and preferably some code as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.