A) // This code should use a loop to raise a number to a power.
int num. bigNum, power, count;
cout << "Enter an integer: ";
cin >> num;
cout << "What power do you want it raised to? ";
cin >> power;
bigNum = num;
while (count++ < power);
bigNum *= num;
cout << "The result is << bigNum << endl;
B) // This code should average a set of numbers, int numCount, total;
double average;
cout << "How many numbers do you want to average? ";
cin >> numCount;
for (int count = 0; count < numCount; count++)
{
int num;
cout << "Enter a number: ";
cin >> num;
total += num;
count++;
}
average = total / numCount;
cout << "The average is << average << endl;
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Database Concepts (7th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Science: An Overview (12th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- #include<stdio.h>#include<stdlib.h> int cent50=0;int cent20=0;int cent10=0;int cent05=0; void calculatechange(int* change){if(*change>0){if(*change>=50){*change-=50;cent50++;}else if(*change>=20){*change-=20;cent20++;}else if(*change>=10){*change-=10;cent10++;}else if(*change>=05){*change-=05;cent05++;}calculatechange(change);}}void printchange(){if(cent50)printf("\n50cents:%d coins",cent50);if(cent20)printf("\n20cents:%d coins",cent20);if(cent10)printf("\n10cents:%d coins",cent10);if(cent05)printf("\n05cents:%d coins",cent05);cent50=0;cent20=0;cent10=0;cent05=0;}void takechange(int* change){scanf("%d",change);getchar();}int main(){int change=0;int firstinput=0;while(1){if(!firstinput){printf("\nEnter the amount:");firstinput++;}else{printf("\n\nEnter the amount to continue or Enter -1 to…arrow_forward#include<stdio.h>#include<stdlib.h> int cent50=0;int cent20=0;int cent10=0;int cent05=0; void calculatechange(int* change){if(*change>0){if(*change>=50){*change-=50;cent50++;}else if(*change>=20){*change-=20;cent20++;}else if(*change>=10){*change-=10;cent10++;}else if(*change>=05){*change-=05;cent05++;}calculatechange(change);}}void printchange(){if(cent50)printf("\n50cents:%d coins",cent50);if(cent20)printf("\n20cents:%d coins",cent20);if(cent10)printf("\n10cents:%d coins",cent10);if(cent05)printf("\n05cents:%d coins",cent05);cent50=0;cent20=0;cent10=0;cent05=0;}void takechange(int* change){scanf("%d",change);getchar();}int main(){int change=0;int firstinput=0;while(1){if(!firstinput){printf("\nEnter the amount:");firstinput++;}else{printf("\n\nEnter the amount to continue or Enter -1 to…arrow_forwardNumber guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if the entered number is larger or smaller than its number. The user then keeps guessing till he/she finds the number. If the user doesn’t find the number after 10 guesses, a proper game over message will be shown and the actual guess is revealed. If the user makes a correct guess in its allowed 10 guesses, then a proper message will be shown and the number of guesses the user made to get the correct answer is also printed. After each correct guess or game over, the user decides to play again or quit and based on the user choice, the computer will make…arrow_forward
- The program segment has errors. Find as many as you can. // This code should use a loop to raise a number to a power. int num, bigNum, power, count;cout << "Enter an integer: "; cin >> num; cout << "What power do you want it raised to? "; cin >> power; bigNum = num; while (count++ < power); bigNum *= num; cout << "The result is << bigNum << end1;arrow_forwardint x1 = 66; int y1 = 39; int d; _asm { } mov EAX, X1; mov EBX, y1; push EAX; push EBX; pop ECX mov d, ECX; What is d in decimal format?arrow_forwardint calculatepower (int x, int y){ if (y > 0) return x* else return 1; int main (){ int num, pwr; cout > num; cout > pwr; cout <« "Number "<arrow_forwardConvert totalMeters to hectometers, decameters, and meters, finding the maximum number of hectometers, then decameters, then meters. Ex: If the input is 815, then the output is: Hectometers: 8 Decameters: 1 Meters: 5 Note: A hectometer is 100 meters. A decameter is 10 meters. 1 #include 2 using namespace std; 3 4 int main() { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 int totalMeters; int numHectometers; int numDecameters; int numMeters; cin >>totalMeters; cout << "Hectometers: cout << "Decameters: cout << "Meters: " << numMeters << endl; " << numHectometers << endl; << numDecameters << endl; 2 3arrow_forwardText-based adventure game: Pretend you are creating a text-based adventure game. At different points in the game, you want the user to select to fight, run, or hide from certain enemies. Modify the application below (week3.py) so that the selection variable is sent as an argument into the choice() function. The user should enter 1 to fight, 2 to run, or 3 to hide in the main(). The choice() function should print one of the three options. You will need to add an if statement in the choice() function to make the correct selection.arrow_forwardchar letter1; char letter2; letter1 = 'y'; while (letter1 <= 'z') { letter2 = 'a'; while (letter2 <= 'c'){ System.out.print("" + letter1 + letter2 + " "); ++letter2; } ++letter1; } For this code why did we use "" before and after in this line? System.out.print("" + letter1 + letter2 + " "); ++letter2; What if we don't use the blank quotation would the output be same? because I don't see the reason for putting those quotation mark.arrow_forwardC++: Describe how the following call by reference works. Make a comment for each line. void pxc(int& c, int& d) { int k = c; c = d; d = k; } int main() { int a = 15, b = 100; pxc(a, b); }arrow_forward2 ii) String character = "Leia"; String planet //L1 = "Alderaan"; //L2 if (character.equals ("Rey")) { planet } //L3 = "Hoth"; //L4 else { planet } "Jakku"; //L5 + planet); //L6 %3D %3D System.out.println(character + at Answer to question 2 ii): Complete the dry run table (you may not need all rows): : LINE character planet character.equals(“Rey")? print Options -arrow_forward#include <stdio.h>#include <stdlib.h> //declaring variables globally to calculate coinsint cent50 = 0;int cent20 = 0;int cent10 = 0;int cent05 = 0; //calculate change//pass change variable by addressvoid calculateChange(int* change) {//calculate change only if change is positiveif(*change > 0) {if(*change >= 50) {*change -= 50;cent50++;}else if(*change >= 20) {*change -= 20;cent20++;}else if(*change >= 10) {*change -= 10;cent10++;}else if(*change >= 05) {*change -= 05;cent05++;}//call calculateChange recursively calculateChange(change);}} // function to display the cents valuesvoid printChange() { if(cent50)printf("\n50 Cents : %d coins", cent50);if(cent20)printf("\n20 Cents : %d coins", cent20);if(cent10)printf("\n10 Cents : %d coins", cent10);if(cent05)printf("\n05 Cents : %d coins", cent05);//reset all cent variables with 0cent50 = 0;cent20 = 0;cent10 = 0;cent05 = 0; } //take change input from user//change variable passed addressvoid TakeChange(int*…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education