Help me fix my errors please!

Write a function (and a main() function to test it) that receives an integer N from the main()
function, generates randomly a sequence of N numbers between (15 – 30), prints them, and
returns the maximum number. The main() prints the maximum number among the
generated N numbers.
I keep getting errors in my code, can someone please help me fix them?

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<cstdlib>
#include<ctime>
#include<iostream>

int mx(int num);
using namespace std;
int main()
{


{
  int num, mx, ctr;

  cout<<"Enter the number of integers to be generated randomly between (15-30): ";

  cin>>num;
  mx= maximum(num);

  cout<<"The maximum number among the generated numbers is: "<<mx;

  return 0;
}

 int maximum(int num)

 {   int mx=0;
     int y;
     srand(time(0);
     for (int ctr=0; ctr<num; ctr++)

      y=15+(rand()%16);
      cout<<"Number "<<ctr++<<":"<<y<<endl;
      if(y>mx)
      mx=y;
  }

  return mx;
}

Delete the open-curly brace from line 11 and the closing-curly brace from line 35. Then, fix your indentation.

Your prototype on line 5 doesn't match any function that actually gets defined later. I imagine you want it to match what's on line 24. Pick a function name and use it for both.
Last edited on
Topic archived. No new replies allowed.