paulus
2009-11-03 19:20:43 UTC
ive tried using different types of while statements to my swich case, but it seems that my "break" clause's are being overridden. if you have a good solution it would be really appreciated
here is a list of my program:
#include
#include
#include
#include
using namespace std;
int main ()
{
bool found=0;
int number=0;
int total=0;
char option=0;
const int arraySize = 10;
int frequency[ arraySize ] = { 0 };
srand(time(0)); // seed random-number generator
for ( int roll = 1; roll <= 100; roll++ )
++frequency[ rand() % 10 ];
while (( option = cin.get ( )) != EOF)
{
cout << "-----------------------------------------------------------------------\n";
cout << " The random generated array is: ";
for ( int face = 1; face < arraySize; face++ )
{
cout << frequency[face]<<" ";
}
cout << endl;
cout << endl;
cout << " \n [R]everse [A]dd [S]earch [E]xit "<< endl;
cout << " \n select an option: ";
cout << option << endl;
switch(option)
{
case 'R':
case 'r':
cout << " The reversed array is: ";
for(int face=10;face < 1;face--)
{
cout << frequency[face]<<" ";
}
cout << endl;
break;
case 'A':
case 'a':
for (int face=1;face< arraySize; face++)
{
total += frequency [face];
}
cout << " the sum of the array is: ";
cout << total << endl;
break;
case 'S':
case 's':
cout << "please insert a number:";
cin >> number;
cout << endl;
for(int face=0;face<=9;face++)
{
if(number==frequency [face])
{
cout<<" the number "<< number<<"has been found at position number "<
}
}
if(found==0)
cout << " the number "<
case 'E':
case 'e':
return 0;
break;
}
}
return 0;
}