cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : Please help
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  Please help

velaphi (30)
The program has to compute four totals:
How many people do not read a newspaper,
how many men older than 40 years read a newspaper or twice a week,
how many woman older than 40 read a newspaper once a week, and
how many men read a newspaper 7 days a week.

#include <iostream>
using namespace std;

int main()
{
int age, numDaysPerWeek, number, i, people;
char gender, m, f;

for (int i = 1; i <= 3; i++)
{
cout << "Person number "<< endl;
cout << i << endl;
cout << endl;


cout << " How old are you? " << endl;
cin >> age;
cout << age <<" years old "<< endl<<endl;

do
{
cout << "What is your gender ? Enter M(for Male)or F(for female) "<< endl;
cin >> gender;
if (gender != 'M' && gender != 'F')
cout << "Type M or F "<< endl;
}while (gender != 'M' && gender != 'F');
cout <<"The gender is ("<< gender <<")"<< endl<<endl;
do
{
cout <<"How many days per week do you read a newspaper? " << endl;
cout <<"Answer 0, 1, 3, 4, 5, 6, or 7 " << endl;
cin >> numDaysPerWeek;
if (numDaysPerWeek >= 0 && numDaysPerWeek >= 8)
cout <<"Enter 0, 1, 2, 3, 4, 5, or 7 "<< endl;
}while (numDaysPerWeek >= 0 && numDaysPerWeek >= 8);
cout <<numDaysPerWeek<<" Times Per week "<< endl<< endl;
}
numDaysPerWeek = 0;
if (numDaysPerWeek == 0)
numDaysPerWeek++;
else
numDaysPerWeek = 0;

cout << "Number of people who dont read newspaper "<< numDaysPerWeek << endl;

return 0;
}
|
Ganon11 (54)
OK, what do you need help with? What is it doing now?
|
kgelders (2)
For starters, think about the logic in this statement:
(numDaysPerWeek >= 0 && numDaysPerWeek >= 8)

Did you mean:
(numDaysPerWeek < 0 || numDaysPerWeek > 7)

|
velaphi (30)
The above code is working just fine, i want to add more to this code. This code must calculate four totals:

How many people do not read a newspaper,
how many men older than 40 years read a newspaper or twice a week,
how many woman older than 40 read a newspaper once a week, and
how many men read a newspaper 7 days a week.
|
firedraco (847)
Just add some check for those specific things, like:

1
2
3
4
5
6
7
8
9
10
if (numDaysPerWeek == 0) {
     var1++;
}else if (gender = 'M' && numDaysPerWeek == 2) {
     var2++;
} else if (gender = 'F' && numDaysPerWeek == 1) {
     var3++;
} else if (gender = 'M' && numDaysPerWeek == 7) {
     var4++;
}
//then output the variables 
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us