Monday, November 30, 2015

// // Leave a Comment

C++ Program To Count Number Of Male And Female Students In A Class

Write a program in C++ to count number of male and female students in class. Print out the number of males, number of females and total number of students.

/**
 *
 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 *
 */ 

#include < iostream >;
using namespace std;

int main () {
    int nMale = 0, nFemale = 0, nTotal = 0, choice, sex;
    cout << "\n   THIS PROGRAM COUNTS AND PRINTS THE NUMBER OF MALES AND FEMALES IN A CLASS\n";
    cout << "   -------------------------------------------------------------------------\n ";
    cout << "Do you want to start? Enter -1 to exit: ";
    cin >> choice;
    while (choice != -1) {
          cout << "\nIs student a male? (1 = yes, 2 = no): ";
          cin >> sex;
          
          if (sex == 1) {
                 nMale += 1;
          } else {
                 nFemale += 1;
          }
          
          nTotal += 1;
                 
          cout << "\nDo you want to start? Enter -1 to exit: ";
          cin >> choice;
    }
    
    cout << "\nThe total number of MALE students = " << nMale;
    cout << "\nThe total number of FEMALE students = " << nFemale;
    cout << "\nThe total number of STUDENTS = " << nTotal;

    return 0; 
}

Click here to see the same program in QBasic.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately.

Thanks.