I am lost

This is what I'm trying to do:
The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a function to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10
(ends in a 0).
If the scores are all valid, the main program will call a function (which will itself call other functions) to classify the group of three scores in various ways.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 #include <iostream>
using namespace std;


int isitavalidgroup(int array[]);

int main()
{

int array[200];

cout <<"Please enter 3 SAT scores"<<endl;

cin>>array[0];
cout<<endl;

cin>>array[1];
cout<<endl;

cin>>array[2];

isitavalidgroup(int array[]);






}

int isitavalidgroup(int array[])
    {
    for(int i=0;i<3;i++)
        if(int array[i]>=200 || int array[i]<=800 )


            cout<<"Valid";

    }
This is what I'm trying to do:

And?

Generally when you ask for help you want to supply some inkling of what you expect and how what's happening differs from what you expect.

Like, if there were compiler errors generated, you might supply them.

Things you might do to address your (unstated) issues:
Read up on how to call a function.
Read up on how one supplies an argument to a function when it is called.
Actually return a value from a function that promises to return a value.
(And since that function probably returns a value for a reason - perhaps you should do something with the value when one is returned.)
Please, don’t let the quantity of requirements depress you. Just go through it by little stages.
Here are some hints:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// The main program will read in a group of three integer values 
// which represent a student's SAT scores.
// The main program will call a function to determine if these three scores 
// are all valid--valid means in the range from 200 to 800, including both 
// end points, and is a multiple of 10 (ends in a 0).
// If the scores are all valid, the main program will call a function 
// (which will itself call other functions) to classify the group of three 
// scores in various ways.
#include <iostream>

using namespace std;

// What if isitavalidgroup() would return a bool?
int isitavalidgroup(int array[]);

int main()
{

    // The main program will read in a group of three integer values 
    // which represent a student's SAT scores.
    int satscores[3];

    for loop: // repeats three times
        cout << "Please enter one SAT scores: ";
        cin >> satscores[] <-- an index is needed here

    // "...call a function to determine if these three scores 
    // are all valid..."
    // isitavalidgroup() returns a value.
    // It could be a good idea to capture, save or use that value.
    isitavalidgroup(int satscores[]); <-- there's an error in the argument list

    // "...If the scores are all valid..."
    // isitavalidgroup() is what tells you if the three scores are valid
    // "...the main program will call a function to classify the group 
    // of three scores in various ways..."
    need another function here...

    return 0;
}

int isitavalidgroup(int array[])
{
    for(int i=0; i<3; i++)
    {
        // "...in the range from 200 to 800, including both end points..."
        // If one of the three values is out of range
        if(int array[i]<200 || int array[i]>800 )
        {
            // returns an error-code
        }
        // "...and is a multiple of 10 (ends in a 0)..."
        else if() // is the value NOT a multiple of 10?
        {
            // returns an error code
        }
    }

    return ... <-- a value that means 'all fine'
} 


Last edited on
It'd be more prudent to check if an input score is valid first before sending it on to the satscores array (or even better std::vector). Once the scores are already in the array and only then any one of them is found to be invalid we have to start all over again
I've tried making some changes and I'm still struggling a great deal. I also can't figure out how to set it up as a bool.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;

bool isitavalidgroup(int array[]);

int main()
{


int array[3];

cout <<"Please enter 3 SAT scores"<<endl;

for(int i=0; i<3; i++)

cin>>array[i];
cout<<endl;

cin>>array[i];
cout<<endl;

cin>>array[i];

bool isitavalidgroup(array[]);




return 0;

}

bool isitavalidgroup(int array[i])
    {
    for(int i=0;i<3;i++)
       {

        if(int array[i]>=200 && int array[i]<=800 )

           {
            return cout<<"Not Valid group";
           }

        else if (int array[i]/10!=0)

           {
            return cout<<"Not Valid group";
           }
       }
        return cout<<"Valid Group";

    }
closed account (48T7M4Gy)
Given that you've decided to check the group rather than individual scores, which is not as good as checking each one as it is entered, your program should look something like this. You need to read your notes, texts and tutorials :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

using namespace std;

bool isValid(int[]);

int main()
{
    int array[3]{0};
    
    cout << "Please enter 3 SAT scores" << endl;
    
    for(int i=0; i<3; i++)
    {
        cin>>array[i];
    }
    
    if( isValid(array) )
        cout << "Group is valid\n";
    else
        cout << "Group is not valid\n";
    
    return 0;
}

bool isValid(int anArray[])
{
    for(int i=0;i<3;i++)
    {
        if( anArray[i] < 200 || anArray[i] > 800 || anArray[i]% 10 != 0)
        {
            return false;
        }
    }
    return true;
}
Hello esokoletsky,

You might find these links useful.

http://www.cplusplus.com/doc/tutorial/variables/#fundamental
http://www.cplusplus.com/forum/beginner/147530/

Your for loop is missing a set of "{}", so everything after line 14 is not part of the for loop on line 14.

Lines 19, 20 and 22 are not needed if lines 16 and 17 are part of the for loop.

Line 24 is the same proto type as line 4 and not a function call. A function call would be more like aBoolVariavle = isitavalidgroup(array[i]); and should be called after each entry not after the for loop. Also you nee to correct any error before the next iteration of the loop so you do not have to start the program over any time there is an error from input.

Your function at line 33 will not work the way you expect because the function returns a bool which is either 0 or 1; false or true and you are trying to return much more than that.

Hope that helps,

Andy
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/212371/
Topic archived. No new replies allowed.