![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Oct 2005
Posts: 5
OS: XP
|
C++ help with arrays..
hi guys. im really having probs with arrays. Basically i open an input file like:
Code:
ifstream infile;
infile.open("A:\\students.txt");
76,89,150,135,200,76,12,100,150,28,178,189,167,200,175,150,87,99,129,149,176,200,87,35,157,189 now what i need to do is to put all those in an array...and then determine the number of students having scroes in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200. it should then display the results like: ------------COUNTS(the total number) 0-24 ------- 1 25-49-------- 2 50-74 --------0 .. ----------- . . ----------- . .. ----------- . . please if someone could help me.... thanks! ive tried some code, but im really stuck:,, this is what ive done: Code:
int list[26];
int z;
infile >> list[26];
while(infile)
{
///for(z = 0; z < 26; z++)
//{
if(list[z] > 0 && list[z] < 25)
{
list[z]++;
sum = sum + list[z];
}
infile >> list[26];
cout << sum;
}
|
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: Oct 2005
Posts: 4
OS: XP Prof
|
Binary Search or Bubble Sort?
Have you tried something like this?
Example of Binary Seach..... int binarysearch (int array[], int size, int searchKey) { int low = 0, middle, high; high = -1; while (low <= high); { middle = (low + high) / 2; if (searchKey == array [middle]) return middle; else if (searchKey < array [middle]) high = middle -1; else low = middle + 1; } return -1; //not found } Does this help? Once it finds the values in the array you should be able to sort them with some more code. |
|
|
|
|
|
#3 (permalink) |
|
TSF Enthusiast
Join Date: Dec 2004
Posts: 604
OS: windows xp
|
PHP Code:
__________________
|
|
|
|
![]() |
| Thread Tools | |
|
|