1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//---------------------------------------------------------------------------
#include <iostream>
#pragma hdrstop
using namespace std;
void displayFirstWay(int, int, char );
void displaySecondWay(int, int, char ); //problem was here
//function prototype has to have same parameters where the call and defition are.
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
int num1;
int num2;
char choice;
int temp;
cout << "enter first number to display: " ;
cin >> num1; //between this number
cout << "enter second number to display: " ;
cin >> num2; //and this number
if (num1 > num2 )
{
temp = num1; //if first number is bigger than second
num1 = num2; // they are swapped
num2 = temp;
}
cout << "Enter your selection ( 'o' or 'e' ): ";
cin >> choice ; //o for odd numbers, e for even numbers
if (choice == 'o')
{
displayFirstWay( num1, num2, choice );
cout << endl;
}
if(choice == 'e')
{
displaySecondWay( num1, num2, choice );
}
system("PAUSE");
return 0;
}
//---------------------------------------------------------------------------
//first function defition
void displayFirstWay( int num1, int num2, char choice )
{
int number;
cout << "Odd numbers are: ";
for(number = num1;number <= num2; number++)
{
if(number % 2 !=0)
cout << number<< " ";
}
}
//---------------------------------------------------------------------------
//second function defition
void displaySecondWay( int num1, int num2, char choice )
{
int number;
cout << ("\nEven numbers are: ");
for(number = num1;number <= num2; number++)
{
if(number % 2 ==0)
cout << number << " ";
}
}
//---------------------------------------------------------------------------
|