Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Field itteration

Posted on 2003-02-24
5
Medium Priority
?
180 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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

571 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