ok so im new at computer programming and im trying to run this program.
yes im takeing a class and this is a project.
I dont need to have the part i need help on done. its just for extra credit but i have no idea why its not working.
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int Students, Student_Age, Total_Age, female, male;
float NumberOFstudents, Average_Age;
string gender;
cout << "Enter the number of students in the class\n";
cin >> Students;
while (Students<=0)
{
cout << "Please enter a correct value. Try again.\n";
cin >> Students;
}
female=0; male=0;
Total_Age=0;
NumberOFstudents=Students;
while (Students > 0)
{
cout << "Enter age of studnet\n";
cin >> Student_Age;
while (Student_Age<=0)
{
cout << "Age has to be greater than 0 try again\n";
cin >> Student_Age;
}
cout << "Enter gender of student with f or m.\n";
cin >> gender;
while ( ((gender != "f") || (gender != "F")) || ((gender != "m") || (gender != "M")) )
{
cout << "Please enter a correct value.\n";
cout << "Remeber (f for girl) (m for guy)\n";
cin >> gender;
} // this while loop is the part that i cant get to work right. it just keeps looping
// over and over again without working.
if((gender == "f")||(gender == "F"))
{
female++;
}
else if((gender == "m")||(gender == "M"))
{
male++;
}
Total_Age+=Student_Age;
Students--;
}
Average_Age=(Total_Age/NumberOFstudents);
if (Average_Age>=100)
{
cout << setprecision(4);
cout << "Average age of students = " << Average_Age << endl;
}
else if (Average_Age>=10)
{
cout << setprecision(3);
cout << "Average age of students = " << Average_Age << endl;
}
else if (Average_Age>=0)
{
cout << setprecision(2);
cout << "Average age of students = " << Average_Age << endl;
}
cout << "Total girl "<< female << endl;
cout << "Total guys "<< male << endl;
cin.get();
cin.get();
return 0;
}
yes i realize that its quite a long and cumberosome(well long to me) code. and a bit messy but
I could have used char for memory but whatever i trust strings more.
and yes i could use a goto loop. but hey what would be the fun in that.
Any suggestions??
I got this far by myself but well i cant figure out why its not working.
it should work. ex ( ((true) || (false)) || (( false ) || ( false )) ) it should be true shouldnt it?
well
any ideas. im probably missing something small