While Loop not workig?!?!
May 6, 2013 at 7:02pm UTC
Hi I have the following loop:
1 2 3 4 5 6 7
while (s!=-1){
cin>>s>>p>>m;
a[s-1][p-1]=m;
}
and when I input -1 for "s", the program wont exit the loop right away, it continues with asking the user for variable "p" and "m"!! How do I fix that!
Thank you for your time!
May 6, 2013 at 7:22pm UTC
1 2 3 4
while ( (cin>>s) && (s!=-1) && (cin>>p>>m) )
{
a[s-1][p-1] = m;
}
May 6, 2013 at 7:25pm UTC
are you asking the user for 's' outside of the loop, because it looks like you are having the user input the value for 's' inside the loop.
Topic archived. No new replies allowed.