//Library function
#include <iostream> //Allow function to preform input and outpuut
#include <string> //Allow the program to preform string function
using namespace std; //Allow to group entities like class
int main() //Function main, program execution begin
{
//Variables declaration
int num[5];
int count;
//for statement use to initialize; number is less than 5; and then increment it;
for(int x=0;x<5;x++)
{
cout <<"Enter num: "; //Prompt user to enter the numbers
cin >>num[x]; //Number is enter and store in [x]
count = num[x]; //Display number
if(num[x] < 1 || num[x] > 20) //Check if number is less than 1 or greater than 20
{
cout<< "You have enter an invalid number" <<endl; //Display error message
}
else
{
if(num[x] % 2 == 0) //Check if the number is even
{
cout<<count;
for(int i=0;i<count;i++) //increment counter for even number
{
cout<<" *"; //Display asterick "*" for even number
}
}
else if(num[x] % 2 == 1) //Check if number is odd
{
cout<<count;
for(int i=0;i<count;i++) //Increment counter for odd number
{
cout<<" #"; //Display number sign "#" for odd number
}
}
cout<<endl;
}
}
return 0; //Return the value of 0
}
J.W. Production
|