I have to create a program for one of my classes. It is extra credit. I am stump as of right now. What is the best way to accomplish this using arrays and strings. And the loops have to be for and while...in case there are others i dont know. Any help or hints would be greatly appreciated.
the program must use a loop to generate 30 random integers between or including 1 and 100 and store those integers into an array.
With a separate loop the program must find and display the maximum value in the array.
Then the program must ask the user to input a value and then search the array for that value with a third loop. If the value is found, the program must display the array position in which the value was found (where the very first position in the array is position zero.) If the value is not found in the array, the program must display the message "Not found".
For full credit, your program must use three loops as described above even if you can simplify the algorithm into fewer loops. Also, you must use this statement srand(1); to initialize the random seed. Do not use srand(time(NULL)); even though it leads to more interesting and varied sets of random numbers.
No pseudocode or test plan must be submitted with this assignment, however your program must be consistent with any sample test plan cases that may have been developed or discussed in class.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You are guaranteed that the user will input a valid integer.
You must hand in the following on separate pages stapled in this specified order:
The hardcopy source code for this assignment. Staple multiple pages together, if applicable.
You must also upload copies of the source file (named a4.cpp) & the executable file (named a4.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.
well i used a random numbers function that looks like this
int main()
{
int num = 0;
// srand(time(NULL));
srand(1);
for (int i = 0; i < 30; i++)
{
num = rand() % 30 + 1;
cout << num << " ";
}
return 0;
}
Next I tried a sort funtion that just flat out didnt work. So i guess this is where im currently stuck. I tried a few other ways but they didnt have any hope.