I am to use one loop to accumulate numbers (and later get average of) and to be a sentinal control (when the user wants to quit).
I think it makes better sense to use 2 loops (nested) but the instructor has insisted on one loop.
Could anyone give me a hint how this could be done. I am a first semester programming student.
thanks in advance.
clski1973 0 Newbie Poster
Recommended Answers
Jump to PostIt is good that you are thinking in terms of separating out functions in your code.
In this case, there is no compelling reason to do it either way. Each loop must iterate through the exact same sequence of numbers.
If you were to use two separate loops …
Jump to PostYou could try something like this: (pseudocode)
int input, average, total, count;
while(count++) { ask for input ; if (input == 0) break; // 0 quits te program total += input; average = total / count; } printf ("Total = %d, Average =%d", total, average;
You'll have to add …
Jump to PostOne other thing, we hadn't eveb touched vectors and arrays yet, Duoas, had to look that up in the book, looks faster than the way we're doing it.
That's the problem with some of the help on boards like this. Many experienced programmers can't tell from someone's code that the …
All 9 Replies
Duoas 1,025 Postaholic Featured Poster
iamthwee commented: glad to see you posting again. +12
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
clski1973 0 Newbie Poster
clski1973 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Duoas 1,025 Postaholic Featured Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.