Help on array problem

First off let me start by saying I am not asking anyone to do my homework for me. I go to every class, take notes, and try to keep up but this computer programming class just does not click with me. I am a math major and for some reason they make us take this class. With that being said...this is my last program of the semester and I am lost..Any help would be greatly appreciated. Here is what we are supposed to come up with and here is what I have now.

Program is supposed to do the following:

//The program prompts you for 10 digits..

Enter 10 digits: 1 3 4 4 3 5 7 3 2 1
1 3 4 4 3 5 7 3 2 1
< = > > = > > = < <

If the number is less than the average it prints out a <, and etc. Here is what I have so far. Any tips would be greatly appreciated.

9 #include <iostream>
10 using namespace std;
11
12 #define n 10
13 int arr [n]
14 int main ()
15 {
16 int n;
17 int i;
18
19 avg = sum/n;
20 n = 0-9;
21
22 cout << "Enter 10 digits: "
23 for (i = 0; i < n; i++)
24 {
25
26 for (i = 0; i < n; i++)
27 if i < n cout << "<" <<;
28 else if i == n cout <<"=" <<;
29 else cout << ">" <<;
30
31 }
32
33 cout << "PROGRAM ENDS" <<;
34 }
35





Hey, I commented your code to explain what's wrong with it. I hope that helps. =)

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
#include <iostream>
using namespace std;

#define n 10
int arr [n]  // missing semi-colon
int main ()
{
    int n;
    int i;

    avg = sum/n;   // avg and sum variables not declared
                            // you must declare the variables before using them.
    n = 0-9;

    cout << "Enter 10 digits: "   // missing semi-colon
                                                // seems to be missing the user input as well. 
    for (i = 0; i < n; i++)
    {
 
        for (i = 0; i < n; i++)
            if i < n cout << "<" <<;    // condition must be inside parenthesis like if ( i < n )
                                                    // can't put nothing on the right hand side of <<

            else if i == n cout <<"=" <<;  // condition must be inside parenthesis
                                                          // can't put nothing on the right side of <<
            else cout << ">" <<; // can't put nothing on the right hand side of <<
 
    }
 
    cout << "PROGRAM ENDS" <<; // cannot put nothing on the right hand side of <<

    // no return value, you must return 0 or an integer
    // because you specified your main function to return an int.
}
Last edited on
Topic archived. No new replies allowed.