Hello all, I have my assignment topic and I know what information I would like to include in my assignment. Can anyone tell me how to put my data into top-down format? Here is what I have thus far:

I'm trying to design a program that will input ages of active duty Navy personnel and then finds the average age of active duty Navy members.


TOPIC- Average age of active duty Navy personnel


Input-current age of personnel
Output- average age of personnel
Subtasks:
UserAges-Input from 50 personnel
AverageAge-Compute average age
Determine average age
Output results

Dani AI

Generated

Top-down design starts at the highest-level task and breaks it into named, testable modules. your list already captures the top level; has the core loop. Turn those ideas into a small set of functions, define what each one receives and returns, and implement them in order so each piece can be tested independently.

A compact decomposition might be:

  • readAges(count) — collect count valid ages (or return how many were actually read).
  • isValidAge(age) — enforce sensible input rules and reject bad entries.
  • computeAverage(ages) — compute the mean and return a double.
  • displayResult(average) — format and output the result.

Example function prototypes:

std::vector<int> readAges(std::size_t requiredCount);
bool isValidAge(int age);
double computeAverage(const std::vector<int>& ages);
void displayResult(double average);

Implementation and testing notes: keep the input count parameterized (use a named constant rather than hard-coding 50). Validate each read: guard against non-numeric input (clear the stream and discard the bad token), ignore negative or implausible values per assignment rules, and allow early termination if required by the spec. When computing the mean, return a floating-point value (cast before division) and check for an empty input set to avoid division-by-zero. For small datasets you can store values in a std::vector<int>; for very large inputs a streaming sum + count is more memory efficient.

Suggested workflow: write and unit-test computeAverage first with hard-coded vectors, then isValidAge, then readAges (with simulated input), and finally wire everything together and add user-friendly error messages. This keeps each step small and verifiable while matching classic top-down design principles.

Recommended Answers

All 2 Replies

Are you looking for c++ code or pseudocode?

declare three integers, one for age, one for sum of ages, and third for number of ages entered.

in a loop
    prompt for age
    update sum
    update counter
end of loop
average age is sum divided by counter

Are you looking for c++ code or pseudocode?

declare three integers, one for age, one for sum of ages, and third for number of ages entered.

in a loop
    prompt for age
    update sum
    update counter
end of loop
average age is sum divided by counter

Thanks for replying, is this the top-down design format?

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.