generate 10 random integers in the range [- 50, 50 ], then outputs the largest among them. What i have tried is
#include <iostream>
#include <ctime>
using namespace std;
int main(){
int startNum = -50;
int endNum = 50;
int rand = 0;
int result = 0;
srand(time(0));
rand = (rand % (endNum - startNum +1 ) +startNum);
int i = 0;
int largestNum = 0;
while (i <9){
result = rand;
if (result > largestNum){
largestNum = rand;
i++;
}
}
cout << "the largest number is " << largestNum << endl;
system("pause");
return 0;
}