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.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> */ <br /><br />#include < iostream >;<br />using namespace std;<br /><br />int main () {<br /> int nMale = 0, nFemale = 0, nTotal = 0, choice, sex;<br /> cout << "n THIS PROGRAM COUNTS AND PRINTS THE NUMBER OF MALES AND FEMALES IN A CLASSn";<br /> cout << " -------------------------------------------------------------------------n ";<br /> cout << "Do you want to start? Enter -1 to exit: ";<br /> cin >> choice;<br /> while (choice != -1) {<br /> cout << "nIs student a male? (1 = yes, 2 = no): ";<br /> cin >> sex;<br /> <br /> if (sex == 1) {<br /> nMale += 1;<br /> } else {<br /> nFemale += 1;<br /> }<br /> <br /> nTotal += 1;<br /> <br /> cout << "nDo you want to start? Enter -1 to exit: ";<br /> cin >> choice;<br /> }<br /> <br /> cout << "nThe total number of MALE students = " << nMale;<br /> cout << "nThe total number of FEMALE students = " << nFemale;<br /> cout << "nThe total number of STUDENTS = " << nTotal;<br /><br /> return 0; <br />}<br /> |