Subprogram errors

Hey, I am having trouble getting this to run. I have never worked with subprograms before and the compiler keeps giving me back errors. I am trying to write a program that if you give a set of numbers the program will give the following back: starting and ending ranges, all the values stored in the arrays, the count of the elements, and the average. There will be two arrays one with values that have 7 in them and one that has values that are divisible by 7.
The compiler gives me errors where there is says here. It says there is conflicting types and declarations.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*MAIN PROGRAM*/
#include <stdio.h>
#include <stdlib.h>
#define MSIZE 500
#define DSIZE 500
int main()
/*Main*/
{
    int mul7[MSIZE]; /*Values that are multiples of 7*/
    int dig7[DSIZE]; /*Values that have 7 in them*/
    int n;           /*Entered Values*/
    int sr;          /*Start Range*/
    int er;          /*End Range*/
    int c7;          /*Multiples of 7*/
    int d7;          /*Digits with 7*/
    double mavg;     /*Average of Multiples*/
    double davg;     /*Average of Digits*/
    
    printf("Enter start and end range values:");
    while((n=scanf("%i%i", &sr, &er))==2)
          {
                          if(sr<0||er>999||sr<er)
                                  printf("range value out of range\n");
                          else
                              {
                                  c7=fmul7(sr,er,mul7,MSIZE);
                                  d7=fdig7(sr,er,dig7,DSIZE);
 Here                      mavg=calcavg(mul7,c7);
                                  davg=calcavg(dig7,d7);
 Here                                  outresults(sr,er,mul7,MSIZE,dig7,DSIZE,c7,d7,mavg,davg);
                                  printf("Enter start and end range values:");
                               }
          }
     if(n !=EOF)
          printf("Input error occurred in scanf\n");
     system("PAUSE");
     return 0;
}
    /*M7*/
    int fmul7(int str, int endr, int mul7[MSIZE], int m7size)
    {
        int ndx;
        int rem;
        int i;
        
        i=0;
        for(ndx=0; ndx<=MSIZE; ndx=ndx++)
         {
                     rem=ndx%7;
                     if(rem==i)
                     {
                               mul7[i]= rem;
                               i = i+1;
                     }
         }
       return i;
    }  
    /*D7*/
    int fdig7(int str, int endr,int dig7[DSIZE], int d7size)
    {
            int q1;
            int num;
            int c7;
            int q2;
            int q3;
            int rem1;
            
            c7=0;
            
            for(num=str; num<=endr; num++)
            {
                         q1=num/100;
                         rem1=num-(q1*100);
                         q2=rem1/10;
                         q3=rem1-(q2*10);
                         if(q1==7||q2==7||q3==7)
                         {
                                                dig7[c7]=num;
                                                c7++;
                         }
            }
            return c7;
    }
    /*Avg*/
   double calcavg(int md7[], int cntmd7)
Here      {
           int ndx;
           int sum;
           double avg;
           
           sum=0;
           avg=0.0;
           
           for(ndx=0;ndx<cntmd7;ndx++)
              sum=sum+md7[ndx];
           if(cntmd7==0)
              printf("Average divisior is zero - skip division \n");
           else
              avg=(double)sum/cntmd7;
           return avg;
      }
     /*Output*/
     void outresults(int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7, int cd7, double mav, double dav)
 and Here     {
          int i;
          
          printf("Start Range=%i  End Range=%i \n", &sr,&er);
          printf("Multiple of 7 count is: %i \n", &cm7);
          printf("Number of Digits 7 count is: %i \n", &cd7);
          printf("Multiple of 7 values are: \n");
          for(i=0; i<cm7;i++)
                   printf("%i\n", &m7[i]);
          printf("Values having digit 7 are: \n");
          for(i=0;i<cd7;i++)
                   printf("5i\n", &d7[i]);
          printf("Multiples of 7 average is : %0.21f\n", &dav);
     }
          
                                                
Declare the two functions before main.
1
2
3
4
5
6
7
8
9
10
11
12
13
// declaration
double calcavg(int md7[], int cntmd7);

int main()
{
  // code
}

// implementation
double calcavg(int md7[], int cntmd7)
{
  // code
}

The reason is that the compiler reads the code in ordered fashion and by the time it finds mavg=calcavg(mul7,c7); in your code it has not yet seen any description of what the calcavg is.
1
2
#include <stdio.h>
#include <stdlib.h> 


I believe that in modern C++, we use:

1
2
#include <cstdio>
#include <cstdlib> 


-------------

1
2
#define MSIZE 500
#define DSIZE 500 


Why not use enums? They're scoped and #macros need to be undefined if you want to eliminate them. Can get messy especially in header files.

 
enum {MSIZE = 500, DSIZE = 500};
@Bourgond Aries: the OP might be using C rather than C++.
@keskiverto: Wouldn't OP be on the wrong board then?
I am using C not C++.

What about at line 103? I am getting an error there as well.

I took out the word void then the program runs but I can get any results just asking to enter the range values.
Actually declared it at the beginning but I still can not get any calculations to work and them to print.
Why do you print addresses of values rather than the values themselves?
Because for the program I need to have the user enter the values not already have values in the program.
Topic archived. No new replies allowed.