Ok, on the assumption that the input is one timezone character per resident:
You have to read characters one by one. For each character, using either CASE or IF ELSE construct increment the count of appropriate counter.
You clearly need four integer-type counters, like the E, C, M, P that you already have, but I would recommend unsigned type and more descriptive names.
What should be the value of counters before any input has been handled?
The total of residents is the sum of the residents of the four zones (and of same type as the zone counts). This can be counted after the input has ended.
You can calculate each percentage directly for printing rather than store in variable.
Calculating a percentage means division and from integral numbers that requires promotion to floating point. Use a
cast:
1 2 3 4
|
unsigned int A;
unsigned int B;
// set A and B
auto ratio = static_cast<double>(A) / B;
|
Header <iomanip> contains stream manipulators std::setw, std::fixed and std::precision. Use them for "professional" format.