?
Solved

Field itteration

Posted on 2003-02-24
5
Medium Priority
?
179 Views
Last Modified: 2010-04-01
if((MyStudents[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].Grade1 >=25)&&
(MyStudents[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].Grade2 >=25))

WriteStringCr ("No one scored less than 25 on both exams");

Ok I have the above, which i know is cumbersome. How do I itterate over all Index's of .Grade1 and .Grade2 and only if they are ALL over 25 the text is printed.

Is there a way of of saying[all Index's]??

thanks
0
Comment
Question by:Lambretta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
Exceter earned 80 total points
ID: 8011978
>> Ok I have the above, which i know is cumbersome. How do I itterate over all Index's of .Grade1 and .Grade2 and only if they are ALL over 25 the
>> text is printed.

Not really when you consider what this does. You could use a loop to do the comparison but that would take more space then what you already have. For example,

int count = 0;
bool pass = true;

while( count < 16 )
{
    if( MyStudents[count].Grade1 < 25 && MyStudents[count].Grade2 < 25 )
        {
            pass = false;
            break;
        }
    count++;
}

if( pass )
    WriteStringCr ("No one scored less than 25 on both exams");

>> Is there a way of of saying[all Index's]??

No.

Exceter
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8014163
I know that this is not your exact situation, and not an answer, but a sort of parallel:   I've found myself with database fields like:
   comment_1
   comment_2
   comment_3
and it is always a pain in the butt.  I just bite the bullet and create an array:

    CStringArray asComments;
    if (rs.comment_1 > "" ) asComments.Add(rs.comment_1);
    if (rs.comment_2 > "" ) asComments.Add(rs.comment_2);
    if (rs.comment_3 > "" ) asComments.Add(rs.comment_3);

then ever after, I can do
    for (int j=0; j< asComments.GetSize(); j++ ) {
        // do something
    }

I don't have any idea what's going on with your code:

    MyStudents[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].Grade1 >=25

is that a 16-dimmension array? Very wierd.  But maybe you can copy it into a 17-dimension array and then itterate across the 17'th dimension.

-- Dan
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8018834
>> I don't have any idea what's going on with your code:
>>
>> MyStudents[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].Grade1 >=25

This checks to see if all of the comma sparated subscripts are greater than or equal to 25. Don't ask me to explain why that works I only know that it does. Try this,

int ar[] = { 1,1,1,0 };

if( ar[0,1,2,3] == 1 )
    cout << "Cool!!!" << endl;
else
    cout << "Oh well." << endl;

Then try it with position 3 set to 1.

>> ...17-dimension array...

Doesn't C++ have a maximum of 12 or 13 subsripts?

Exceter
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8018851
>> This checks to see if all of the comma sparated subscripts are greater than or equal to 25. Don't ask me to explain why that works I only know that it does.

Please ignore that!!!

I didn't test that sufficently. Boy do I feel foolish! :-)

Actually it uses the last number in that string and makes the comparison. Basicly, ifs output would hinge on position 3 and all other values would be ignored.

Sorry about that!

(Sheepish)

Exceter
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9845931
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to Exceter: Grade A

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question