HomeToddlersHelp with a C + + program on the search of a female teenager and a male child.?
Posted in Toddlers on 1st December 2012

help with a C + + program on the search of a female teenager and a male child.?
char sex / / ‘M’ == male ‘F’ == weiblichenint age / / Infant age of less than 2 / / infants age greater than or equal to 2 and less than 4 / / child age greater than or equal 4 and less than 13 / / teen-age greater than or equal 13 less than 20 / / adult age greater than or equal to 20 and less than 55 / / senior age greater than or equal 55Basierend on the above information, write a program that finds teenage girls and male child. The output should look like this: Please fill in the following Informationen.Geschlecht: Age: A female or a male child or teenager not found a teenage girl is still a male child found indicating one of the two messages on the result of the input data basiert.Dies my code so far # include “stdafx.h” # include # include using namespace std int _tmain (int argc, _TCHAR * argv []) {int age, char gender; cout <<"Enter Sex:"; cin Sex >> cout <<"age"; cin >> age if ((sex == M) | | (sex == F) && (age <2)) {cout <<"Infant"; } else if ((sex == M) | | (sex == F) && (age> = 2 && age <4)) {cout <<"Toddler"} else if ((sex == M) | | (sex == F) && (age> = 4 && age <13)) {cout <<"Child"} else if ((sex == M) | | (sex == F) && (age> = 13 && age <20)) {cout <<"teen";} else if ((sex == M) | | (sex == F) && (age> = 20 && age <55)) {cout <<"Adult"} else if ((sex == M) | | (sex == F) && (age > = 55)) {cout <<"Senior"} else if (Alter! = 100) {cout <<"nNeither a teenage girl still found a male child n".} return 0;} thanks for the comments you after going through some other examples that I have gone through it again on the left. This is what I came up with this: # include "stdafx.h" # include # include using namespace std int _tmain (int argc, _TCHAR * argv []) {int age, char gender; cout <<" Please fill in the following information. " <> Sex; cout <<""; cin >> age if ((sex == ‘M’) | | (gender == ‘F’) & , & (age <2)) {if (gender == 'M' && age <2) cout <<"nA male infant found" < = 2 & , & age <4)) {if (gender == 'M' && age> = 2 && age <4) cout <<"nA male infant found" < = 2 && age <4) cout <<< = 4 && age <13)) {if (gender == 'M' && age> = 4 && age <13) cout <<"nA male Best Answer (s):
make

response from Peter H
It’s a good start, but a couple of comments, because your code is not without fault kompilieren.Erstens the sex variable of type char. If you specify the value of a char, you must be enclosed in single quotes him, ‘M’ or ‘F’. Secondly, the logic of the program does not answer the question. It should be one of the three outputs: “Found Female Teenager” “Male child found” “found neither female teenager male child” So you need only 2 logical tests to write to each of which a particular gender and age group. You have shown you know how lucky to tun.Viel.

response from zimbo
here is my source code for a program to count the age and gender of people entering a cinema has been. then there’s the average age, lowest and highest age Alter.Ich know it’s not exactly what you are looking for, but you could change my code to use it. for your work – Compiled with wxDev C + + ______________________________________________ / / This program takes keyboard input by age and sex and outputs / / The average age, number of males or females and the youngest and oldest participants # Include Using namespace std; int main () / / Variables declare {int age, int count, int children, young adults int, int midlife; oldAdult int, int pensioners int sum; averageAge int, int youngest, oldest int, char sex, int male, female int ;/ / initialize variables count = 0, children = 0; young adults = 0; midlife = 0; oldAdult = 0; pensioners = 0, sum = 0; oldest = 0; Recent = 1000, male = 0, female = 0; cout <<"Enter the age of participants (-1 to quit): "/ / request for primer read cin >> age; / / This is the first input while (age! = -1) / / sentinel value (an input of -1 leaving the loop {cout <<"Enter your gender (M or F):" / / request for user input cin >> sex, (if if ((age> = oldest) && (age> = 0)) {oldest = age} (age <= youngest) && (age> = 0)) {= youngest age / / age check} if (age <= 18 && age> = 0) {+ + Kids; counting + + , sum = sum + age;} if (age <= 30 && age> = 19) {+ + young adults; count + +; sum = sum + age;} if (age> = 31 && age <= 40) {+ + midlife; count + +; sum = sum + age;} if (age> = 41 && age <= 60) {+ + oldAdult; count + +; sum = sum + age; } if (age> 60) {+ + pensioners; count + +; sum = sum + age;} / / check if sex (gender == ‘m’ | | gender == ‘M’) {times + +;} if (gender == ‘f’ | | gender == ‘F’) {female + +;} cout <<"Enter the age of participants (-1 to quit):"; cin >> age;} cout <

Related Post for Ideas For Getting Your Youngster Prepared For Childcare

The Finest Academic Apps for Youngsters
Issues to do in Milton with Youngsters
Issues to do in Oakville with Youngsters
How To Train Your Little one About Self Management
Ideas For Getting Your Youngster Prepared For Childcare