loop

my program is not finished but every time i try to run it it only loop 3 time before it end but i want it to loop as many time as user wants and if the user wants to end it they just hit q or Q to end the program
#include<iostream>
#include<string>
#include<iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;


int main()
{

int size;

cout << "please select a number between 15 to 20: ";
cin >> size;

int *arrayx = new int[size];

srand((unsigned)time(0));

for (int x = 0; x < size; x++){
arrayx[x] = 1 + (rand() % 20);
cout << arrayx[x] << ", ";
}

cout << "\n[P]osition, [R]everse, [A]verage, [S]earch, [Q]uit " << endl;

char option;

do{ //THIS IS MY DO WHILE LOOP

cout << "\n\nPlease select an option: ";
cin >> option;


if (option == 'p' || option == 'P'){
cout << "\nthe program displays the array elements position and value pairs for all member elements of the array" << endl;
for (int sh = 0; sh < size; sh++){
cout << setw(2) << "element [" << sh << "] is " << arrayx[sh] << endl;
}
}

else if (option == 'r' || option == 'R'){
cout << "\nthe program displays the reversed version of the array" << endl;

reverse(arrayx, arrayx + size);
cout << "\nyour reversed version is: ";
for (int i = 0; i < size; i++){
cout << arrayx[i] << ", ";
}
}

else if (option == 'a' || option == 'A'){
cout << "\nthe program calculates and displays the average of the array elements" << endl;
float sum = 0;
for (int alexis = 0; alexis < size; alexis++){
sum += arrayx[alexis];
}
cout << "the average is " << sum / size << endl;

}

else if (option == 's' || option == 'S'){
cout << "\nthe program asks the user to insert an integer number and look for it in the array, returning the message wheher the number is found and its position(including multiple occurences), or is not found." << endl;
}
option++;

} while (option != 'Q' && option != 'q'); // DO WHILE LOOP
cout << "see you next time " << endl;
delete[] arrayx;

system("pause");
return 0;
}
Welcome to cplusplus.com! Please use code tags when posting code http://www.cplusplus.com/articles/z13hAqkS/
The code tags will help us refer to specific lines, and they also highlight your code to make it easier for us to read :)

Can you tell me why you have option++; near the end of your do-while loop? This line is causing 'p' to become 'q'. Look at an ASCII encoding table to see why http://www.asciitable.com/
Topic archived. No new replies allowed.