473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Write C++ program to find how many students with age range of:

Question:
24students registered to the class. Write C++ program to find how many students with age range of:
//- less than 25
//- 26-30
//- 31-40
//- 41 and above

Please try to help me to write the above program.I have written some lines of code for taking the input value from user for number of students. Is there any function available for storing the input values from user.
coulud anyone please send the solution for the above program.


#include <iostream>
using std::cout;
using std::cin;
using std::endl;
main()
{

int numberofstudents=0;
int age=0;
int count=1;
cout<<"enter number of students"<<endl;
cin>>numberofstudents;
count=numberofstudents-1;

cout<<"enter their age"<<endl;

while(!numberofstudents <= count )

{

cin>>age;
cout<<"age=="<<age<<endl;


count--;
}
return 0;
}
Jul 16 '07 #1
2 4107
sanctus
84
You could define some variables for the age groups, eg x25,x27,x31 and x41 and initialize them to zero. Then between your cin and cout in the while loop you put something like
Expand|Select|Wrap|Line Numbers
  1. if (age < 25) x25=x25+1;
  2. else if (age<31) x27=x27+1;
  3. ...
  4.  
and then cout<<x25 etc should give you the seeked answer
I think it should work, if it doesn't store the preceeding values of the x(...) (that would be the case if all cout's would give 0 or 1) just define them as static int...



Question:
24students registered to the class. Write C++ program to find how many students with age range of:
//- less than 25
//- 26-30
//- 31-40
//- 41 and above

Please try to help me to write the above program.I have written some lines of code for taking the input value from user for number of students. Is there any function available for storing the input values from user.
coulud anyone please send the solution for the above program.


#include <iostream>
using std::cout;
using std::cin;
using std::endl;
main()
{

int numberofstudents=0;
int age=0;
int count=1;
cout<<"enter number of students"<<endl;
cin>>numberofstudents;
count=numberofstudents-1;

cout<<"enter their age"<<endl;

while(!numberofstudents <= count )

{

cin>>age;
cout<<"age=="<<age<<endl;


count--;
}
return 0;
}
Jul 17 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Where are you storing the information for the 24 students??

All you have are single variables.

I would have thought you would acquire the information and then process it according to the problem requirements.
Jul 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really...
2
by: Randy | last post by:
How do you do a find on a range of Dates in a Date field from the find dialog box?
4
by: Darius | last post by:
How to distribute a C program into many C files ? this is the first question a C programmer asks after learning C basics, Questions like --what is a header file --where should i put global...
5
by: Larry__Weiss | last post by:
Can a C# program find out what language an assembly (or components thereof) is written in? - Larry
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.