I have made three functions. I have yet to make more functions. On selectseries function, I have entered the parameter as Enterchoice. Not sure if that is correct, but can someone check it to make sure if its correct. Later On, in my main function, I have use the select series function, but im getting an error on Enteroption function insice the parenthesis. May I know whats wrong?
//Function will prompt the user to enter the option they want the computer to read
int EnterOption()
{
//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 variable for number that will store the user option
int number;
//Prompt user to enter option and enter number
cout<< "\n\nEnter Option: ";
cin>>number;
//If the user enters in zero, Exit the program
if (number==0)
{
cout<<"\n\nProgram Will Terminate";
_getch();
return 0;
}
//if the user enters the wrong number, it will ask again
while (number <1 || number >12)
{
cout<<"\nInvalid Entry";
cout<<"\n\nEnter Valid Option: ";
cin>>number;
}
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)
{
cout<<counter;
cout<< " ";
}
counter++;
}
}
//Function where the uuser choice will tell what series to use
//EnterOption is use to see what value will be inputed here in this parameter. If its one it will use a certain formula
void selectseries (int EnterOption())
{
//If the Enteroptions returns a value of one, you will use powersereies 1 function
if (EnterOption()==1)
{
print_series1(EnterOption());
}
}
int _tmain(int argc, _TCHAR* argv[])
{
EnterOption();
selectseries( EnterOption());
_getch();
return 0;
}
Can I not use it though? I'm going to solve that function inside the parameter. Suppose, the fuction will return a value of one. So selectseries would become (selectseries(1))
void selectseries (int option)
{
//If the Enteroptions returns a value of one, you will use powersereies 1 function
if (option==1)
{
print_series1(option);
}
}
I don't think that you wanted to call EnterOption() twice?