Answers: Source Code (Edit The Source Code Below and Paste Your Updated Program)
Answers: Source Code (Edit The Source Code Below and Paste Your Updated Program)
Answers: Source Code (Edit The Source Code Below and Paste Your Updated Program)
The following question support the attainment of Course Intended Learning Outcomes (CILO): Design
computing based solution using control structures, functions, array and other statements
INSTRUCTION: Write a program the will let the user to enter a number and display the output based
on CHOICES below.
ANSWERS: SOURCE CODE (EDIT THE SOURCE CODE BELOW AND PASTE YOUR UPDATED PROGRAM)
#include <iostream>
main()
{
int num, ctr, trans = 0;
int sum, prod;
do{
cout << "\n\n Enter transaction: ";
cin >> trans;
switch (trans){
case 1:
ctr = 1;
do{
cout << ctr << " ";
ctr++;
} while (ctr <= num);
break;
case 2:
ctr = 1;
while (ctr <= num){
cout << ctr << " ";
ctr++;
}
break;
case 3:
ctr = num;
while (ctr >= 1){
cout << ctr << " ";
ctr--;
}
break;
case 4:
ctr = num;
do{
cout << ctr << " ";
ctr--;
} while (ctr >= 1);
break;
case 5:
ctr = 1;
do{
if (ctr % 3 == 0){
cout << ctr << " ";
}
ctr++;
} while (ctr <= num);
break;
case 6:
ctr = 1;
while (ctr <= num){
if (ctr % 8 == 0){
cout << ctr << " ";
}
ctr++;
}
break;
case 7:
ctr = 1;
sum = 0;
do{
sum = sum + ctr;
ctr++;
} while (ctr <= num);
cout << "The sum is " << sum;
break;
case 8:
ctr = 1;
prod = 1;
while (ctr <= num){
prod = prod * ctr;
ctr++;
}
cout << "The product is " << prod;
break;
default:
cout << "Invalid";
} //end of switch
} while (trans <= 8); // end of do while
} //end of main