Cant i write like this?

Mar 4, 2019 at 7:23pm
How could I store I in p if not?
 
if (num%i == 0) i >> int p;
Last edited on Mar 4, 2019 at 7:23pm
Mar 4, 2019 at 7:26pm
No. That is not valid syntax.
Try:
1
2
3
4
5
int p = 0;
if (num % i == 0)
    p = i;
else
    // handle other logic 
Last edited on Mar 4, 2019 at 7:27pm
Mar 4, 2019 at 8:16pm
you may have seen something a little like what you are trying to do with stringstreams where the stream data is shoveled into a variable using syntax not far off from what you did; that is an advanced topic and the syntax is unlike the way the language does things normally.

if you are confused by an example, post a little of it here and show us what you saw.
otherwise, follow the form provided by Ganado.

Also beware putting variable creation inside conditional blocks for now. You may create problems for yourself until you get a handle on variable lifespans / scopes.
Topic archived. No new replies allowed.