int EnterOption()
{
//Tell use to enter in a choice
cout<<"Choices Listed";
//Display all the choices
//The counter is set to 1. Printing out the text in a quicker way. Displaying text on screen.
int counter=1;
while(counter<=9)
{
cout<<"\n\n\t" <<counter<< ".] Print all the numbers between 1 and 1000 that are divisible by "<< counter;
counter++;
}
//Display the other three options
cout<<"\n\n\t10.] Print all the numbers between one and thousand";
cout<<"\n\n\t11.] Print all the even numbers between one and thousand";
cout<<"\n\n\t12.] Print all the odd numbers between one and thousand";
//Declare a variable for the choice user will enter
int number;
//Perform a do while loop. If the user enters in a number not in the range it will ask user to enter it again
do
{
cout<<"\n\nEnter Choice: ";
cin>>number;
}
//Repeat the loop if its not in the range
while (number<0 || number>12);
return number;
}
//Function will print out the number that is divisible
void print_series1(int divisible)
{
//Making a variable that will divide the divisble number by each number to 1000
int counter;
int remainder;
counter=1;
cout<<endl;
//While counter is less then 1000 it will print out the divisible numbers
while (counter<=1000)
{
//formula for finding the remainder
remainder=counter%divisible;
//If remainder=0, the print out the divisible number
if (remainder==0)
{
//Print out the counter. These counter will be divisible numbers
cout<<counter;
cout<< " ";
}
//Incrememt counter by one
counter++;
}
}
EnterOption();
//You want a value from enteroption. Set a variabel that will store enteroption value into new variable
int StoreEnterOptionValue;
StoreEnterOptionValue==EnterOption;
I have the value of enteroption saved in the variable storeneteroptionvalue; however, I don't want the the program to ask me for a choice again.
Choice Listed:
1.) Print all the numbers between one and thousand";
2.)Print all the even numbers between one and thousand";
3.)Print all the odd numbers between one and thousand";
.........
Enter Choice: 0
Choice Listed:
1.) Print all the numbers between one and thousand";
2.)Print all the even numbers between one and thousand";
3.)Print all the odd numbers between one and thousand";
.........
Enter Choice:
Rather then the program askingme twice I want it to ask me once. I know the problem lays in that storeenteroptionvalue=enteroption. I just want to store the value from enteroption intothat function.
//Call the function enteroption to allow the user to enter in a number
EnterOption();
//You want a value from enteroption. Set a variabel that will store enteroption value into new variable
int StoreEnterOptionValue;
StoreEnterOptionValue=EnterOption();
//If Select Series=0, terminate the program
if (StoreEnterOptionValue==0)
{
cout<<"\n\n\tExecution Error";
_getch();
return 0;
This is how I revised my code and yet i'm still getting the same error. I'm using "zero" value as my test sample. It asks me to enter in a choice and I enter in zero. As I clarified before, it asks me for the enter choice again. When I enter in zero this time. It states Execution error and it terminates :) I just want the program to ask me once, rather then twice