Array Programming Problem

i have an assignment where i need to write a program that generates an array filled up with random positive integer number ranging from 60 to 100, and display it on the screen. After the creation and displaying of the array, the program displays the following:
[R]everse [A]dd [S]earch E[xit]
Please select an option:_
Then, if the user selects:
- R (lowercase or uppercase): the program displays the reversed version of the array.
- A (lowercase or uppercase): the program displays the sum of the elements of the array.
- S (lowercase or uppercase): the program asks the user to insert an integer number and
look for it in the array, returning a message whether the number is found and its position
(including multiple occurrences, see example below), or is not found.
- E (lowercase or uppercase): the program exits.
NOTE: Until the last option (ā€˜eā€™ or ā€˜Eā€™) is selected, the main program comes back at the
beginning, asking the user to insert a new integer number.

This is my code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;
int linearSearch(const int[], int, int);

int main()
{
char option;
{
int search, array[10];
for (int x = 0; x < 10; x++);
{
cout << setw(10) << (rand() % 40 + 61);
}
cout << "\nR Reverse Version of Array";
cout << "\nA Sum of Elements of Array";
cout << "\nS Search for Number in the Array or if it is not found";
cout << "\nE Exit Program \n";

cout << " Please Select An Option:";
cin >> option;

if (option == 'R' || option == 'r')
{
cout << "Reverse Version of Array=" << endl;
}
else if (option == 'A' || option == 'a')
{
cout << "Sum of Array =" << endl;
}
else if (option == 'S' || option == 's')
{
cout << " Please enter a Number in the Array to Search for " << endl;
cin >> search;
}
while (option != 'E' && option != 'e')
{
cout << " Exit Program";
cout << endl;
}
return 0;
}
}
but it doesnt have the random generated array and when i run it and press anything it doesnt work but it doesnt have any errors
Hi @dconc,
First of all you might want to put the values inside the array, then display it. If you don't do that, the compiler will assign random values to the components.
Instead of:
1
2
3
4
for (int x = 0; x < 10; x++);
{
    cout << setw(10) << (rand() % 40 + 61);
}

Try this:
1
2
3
4
5
6
//also here you used a ';', which just makes the loop do nothing besides incrementing x.
for (int x=0; x<10; x++)
{
    array[x]=rand()%40+61;
    cout<<array[x];
}

Hope this helps.
Topic archived. No new replies allowed.