-
July 15th, 2008, 09:20 AM
#16
Re: While loop crash
Originally Posted by Archetype
Then I do mean lurk
As a funny side note - I went to bed right before reading about While loops last night, which is partway through chapter 4. Doh! As soon as I read the correction I opened my book, and saw the proper syntax for a while loop.
/begin lurking
Even those of us that have been doing this a while make silly mistakes in our posts here sometimes. It happens.
-
July 15th, 2008, 11:50 AM
#17
-
July 15th, 2008, 09:30 PM
#18
Re: While loop crash
I got it working thanks for the help guys. All i needed to change was <= 3 to !=3. Only thing is now its adding wrong but that should be easy to fix. Adam
Code:
#include <iostream>
using namespace std;
void main ()
{
int num1,
num2 = 0,
total;
while (num1 != 3)
{
total += num2;
num1++;
cout << "Please enter a number.\n";
cin >> num2;
}
cout << total;
}
-
July 15th, 2008, 09:52 PM
#19
Re: While loop crash
Originally Posted by blobs
I got it working thanks for the help guys. All i needed to change was <= 3 to !=3.
I don't think you did. You got a fix in the very first reply to your post (see post #2), but chose to ignore it...
Good luck!
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 15th, 2008, 09:56 PM
#20
Re: While loop crash
Originally Posted by blobs
I got it working thanks for the help guys. All i needed to change was <= 3 to !=3. Only thing is now its adding wrong but that should be easy to fix. Adam
Try:
Code:
#include <iostream>
using namespace std;
void main ()
{
int num1 = 0,
num2 = 0,
total = 0;
while (num1 <= 3)
{
cout << "Please enter a number.\n";
cin >> num2;
total += num2;
num1++;
}
cout << total;
}
-
July 16th, 2008, 07:51 AM
#21
Re: While loop crash
Originally Posted by dizuane
Try:
Code:
#include <iostream>
using namespace std;
void main ()
{
int num1 = 0,
num2 = 0,
total = 0;
while (num1 < 3)
{
cout << "Please enter a number.\n";
cin >> num2;
total += num2;
num1++;
}
cout << total;
}
The requirement was for it to execute 3 times.
-
July 16th, 2008, 03:47 PM
#22
Re: While loop crash
Yah just caught that.
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
|