Question:
Someone Help.. Loop wont continue?
Think Big Lift Big
2009-11-19 15:42:25 UTC
Hi, Someone please tell me what's the problem with this loop, it stops after checking the if statement and doesnt go on to the last statement in the while loop (basically all im doing is checking if conc is equal to strpr, break out of loop and continue to next portion of program, BUT if its not, continue to the next portion of the while loop which is acctrdin.getline(str1, 20);

All help appreciated.. thanks
string strpr, str1, conc;
conc = uname + pwd;
//acctrdin is connected to a file
while (!acctrdin.eof())
{
strpr = str1;
if (strpr == conc)
{
cout << "Verified." << endl;
break;
}
acctrdin.getline(str1, 20);
}
Three answers:
tbshmkr
2009-11-19 15:57:47 UTC
Get rid of the break.

=

Use if (strpr == conc)

{

cout << "Verified." << endl;

}

else ...
oops
2009-11-19 15:54:54 UTC
There's no problem with the loop. If it's breaking out, that's because strpr is equal to conc. If that's not what you intended, then there is something else wrong with your code, it's not this loop.
fitzgerald
2016-10-18 09:28:50 UTC
#contain iostream utilising namespace std; int substantial() { string shape; double length, width, top, base, radius, section; double p = 3.14; at an identical time as(authentic) { cout<>shape; cout<>length; cout<>width; section=length*width; cout<>base; cout<>top; section=(top*base)/2; cout<>radius; section=p*(radius*radius); cout<>ans; if (ans=="y" || ans=="Y") proceed; else wreck; cout<


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...