QUESTION 1a.
while(age>30||finalMark<65)
{
cout<<”Candidate not suitable.”<<endl;
cout<<”Enter age: “;
cin>>age;
cout<<”Enter final mark: “;
cin>>finalMark;
}
QUESTION 1b.
CODE OUTPUT
a. for(int i=1;i<=1;i++) *
cout<<”*”;
cout<<endl;
b. for(int i=2;i>=2;i++) Endless loop of *
cout<<”*”;
cout<<endl;
c. for(int i=1;i<=1;i--) Endless loop of *
cout<<”*”;
cout<<endl;
d. for(int i=12;i>=9;1--) ****
cout<<”*”;
cout<<endl;
e. for(int i=0;i<=5;i++) ******
cout<<”*”;
cout<<endl;
f. for(int i=1;i<=5;i++) Syntax error.
cout<<”*”; “i” is inaccessible after the for loop.
i=i+1;
cout<<endl;
QUESTION 1c.
,PROGRAM.
#include <iostream>
using namespace std;
int main()
{
int i=0;
while(i<=10)
{
if (i<5 && i!=2)
cout<<"X";
i++;
}
return 0;
}
Output.
QUESTION 1d.
, PROGRAM.
#include <iostream>
using namespace std;
const int LIMIT =10;
int main()
{
float counter;
//The declaration of variables can be on the same line separated by a comma.
int number, zeros, odds, evens;
//The counter variables are inirialised to assure that they don’t acquire an unknown initial value.
zeros=0;
odds=0;
evens=0;
cout<<"Please enter "<<LIMIT<<" integers, positive,negative or zeros."<<endl;
cout<<"The number you entered are "<<endl;
for(counter=1;counter<=LIMIT; counter++)
{
cin>>number;
switch(number%2) //The switch statement is working on a remainder and (%) is used.
{
case 0:
evens++;
if (number==0) //correcting the boolean operator for number is equal to zero…(==) not (=)
zeros++;
break;