This quiz was also separated into two parts… the first one is able to ask for two different numbers to the user and calculate with a power function, the first number to the power of the second number.
//CODE 1:
# include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[]) {
int num1, num2, R;
std::cout << “This program makes the power function between number 1 and number 2.” << std::endl;
std::cout << “Please enter number 1” << std::endl;
std::cin >> num1;
std::cout << “Please enter number 2” << std::endl;
std::cin >> num2;
R=pow (num1, num2);
std::cout << “The final result is… ” <<R << std::endl;
return 0;
}
This code is able to print a certain number of stars with a value given by the user. Using a function called “stars” and a loop.
//CODE 2:
#include <iostream>
using namespace std;
void stars(int s) {
int count=0;
do {
std::cout << “*” << std::endl;
count++;
} while(count!=s);
}
int main(int argc, char const *argv[]) {
int s, count;
std::cout << “This program prints the stars you ask for.” << std::endl;
std::cout << “Please enter the number of stars you want to print in the console.” << std::endl;
std::cin >> s;
stars(s);
return 0;
}
QUIZ 2 by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.