By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Loop help plz

P: 4
Hi guys, I have to write a program with a loop that stops at the user's inputted sum.
A sample output would be this.

Enter your test value 123
Even integer Sum
2 2
4 6
6 12
8 20
10 30
12 42
14 56
16 72
18 90
20 110
22 132

My problem is that I cannot figure out how to stop the loop at the user's defined sum. Any assistance on this would be greatly appreciated. Thanks.
Nov 17 '06 #1
Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
err

Expand|Select|Wrap|Line Numbers
  1. while(sum <= inputValue)
  2. {
  3.    ...
  4. }
  5.  
Nov 17 '06 #2

Expert
P: 96
Enter your test value 123
Even integer Sum
2 2
4 6
6 12
8 20
10 30
12 42
14 56
16 72
18 90
20 110
22 132

Where from the values in bold came? are those input from user.
If test value is 123, should it stop at/just next to 123?

Please post your program with the above questions answered.
Nov 17 '06 #3

P: 4
Heres the exact instructions:

Program Description: Write a program that will continue to sum up all even integers until their sum exceeds (or is equal) to an amount inputted by the program user. Print out the sum and the test value.
Nov 17 '06 #4

P: 4
ah, what banfa wrote looks good, but unfortunately I can't try it until i get to school tomorrow =/
Nov 17 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.