I am trying to command my program to reverse a set of random array numbers. I get my program to come up with 10 digits, (ranging from 60-100) and when the random array is generated, I get it to give me 4 options; ex:
66 75 84 93 82 61 66 99 85 93
R - for reverse. (this will reverse the array set to[93 85 99 66...84 75 66])
S - for search. (this will prompt you to search a number and read what line it'll be located in. )
E - for exit. (to exit the program )
A - for add.. (this will add up all the random array number set.)
Everything works great but the only issue I am having is that it won't reverse the random generated array set. I thought I promoted the correct command. I need help with this, please keep in mind I am new to C++.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
srand(time(0));
int arr[10],i,sum;
bool found;
char choice;
for (i = 0; i < 10; i++){
arr[i] = rand() % 30 + 60;
}
cout << "The random generated array is: \n";
for (i = 0; i <10; i++){
cout << arr[i] << " ";
}
cout << "\n\nR[reverse]\t[S]search\t[E]exit\t\t[A]add\nSelect an option: ";
cin >> choice;
switch (choice){
main ();
case 'R':
case 'r':
cout << "\nThe reversed array is: ";
for (i = 9; i >=0; i--)
cout << endl << endl << "------------------------------" << endl;
main ();
case 'A':
case 'a':
cout << "\nThe sum of the array element is ";
sum = 0;
for (i = 0; i < 10; i++) sum += arr[i];
cout << sum << "\n";
cout << endl << endl << "----------------------" << endl;
main ();
case 'S':
case 's':
cout << "\nPlease insert an element to find: ";
int find;
found=false;
cin >> find;
for (i = 0; i<10; i++){
if(arr[i] == find){
if(i ==0)
cout << "\nThe number " << find << " has been found at the 1st position" << endl;
else if(i == 1) cout << "\nThe number " << find << " has been found at the 2nd position" << endl;
else if(i == 2) cout << "\nThe number " << find << " has been found at the 3rd positon" << endl;
else if(i == 3) cout << "\nThe number " << find << " has been found at the 4th position" << endl;
else if(i == 4) cout << "\nThe number " << find << " has been found at the 5th position" << endl;
else if(i == 5) cout << "\nThe number " << find << " has been found at the 6th position" << endl;
else if(i == 6) cout << "\nThe number " << find << " has been found at the 7th position" << endl;
else if(i == 7) cout << "\nThe number " << find << " has been found at the 8th position" << endl;
else if(i == 8) cout << "\nThe number " << find << " has been found at the 9th position" << endl;
else if(i == 9) cout << "\nThe number " << find << " has been found at the 10th position" << endl;
found = true;
}
}
if(found) cout << "\nElement not found\n";
cout << endl << endl << "----------------------" << endl;
main();
case 'E':
case 'e':
break;
}
return 0;
}
Edited: Ok I just posted the entire code so you can see a little bit better in debt. That was my fualt. sorry.