Answer to Question #146599 in C++ for mael

Question #146599
Write a program that accepts a series of genders from a class of 10 and counts the number of female and male in the class.
1
Expert's answer
2020-11-25T10:07:35-0500
#include <iostream>

int main() {
    const int size = 10;
    char genders[size];
    for(int i = 0; i < size; i++) {
        std::cin >> genders[i];
    }
    // count
    int male = 0, female = 0;
    for(int i = 0; i < size; i++) {
        if(genders[i] == 'F') {
            female++;
        }
        else {
            male++;
        }
    }
    std::cout << "Males: " << male << "\nFamales: " << female << std::endl;
    return 0;
}

// Input example:
F M F F F M M F F M
// Output:
Males: 4
Famales: 6

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog