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?
#include<cstdlib>
#include<ctime>
#include<iostream>
int mx(int num);
usingnamespace 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.