Question

In: Electrical Engineering

Edit the given program to produce the following output in c++ mode: - Take in the...

Edit the given program to produce the following output in c++ mode:
- Take in the name of a superhero & tell him how many villains he/she has to defeat today - The number of villains is randomly generated and should be a number between 11 and 42.
- Use a seed of 7.
Hint: Compile the program first before making edits

What is your name?
Hello Captain America
There are 42 villains you need to defeat today
Oops! one of the villains was able to multiply himself by  a power of 3.
There are actually 74088 villains.

the program starts her

#include <string>                                  //make sure that all necessary libraries are included & correct
using namespace std;

int main() {
string name;
int number;

  
   cout << "What is your name?" << endl;
   cin >> name;
   cout << "Hello " << name << endl;
   cout << "There are "<< number >> " villains you need to defeat today"<< endl;          // edit and include any necessary code
   cout << "Oops! one of the villains was able to multiply himself by a power of 3. There are actually villains." << endl;
  
  
  

   return 0;
}

Solutions

Expert Solution

The code is well commented and given below. Also the screenshot of the output and code itself is provided for better readability. Please go through the comments and if any doubts persist feel free to leave a comment asking clarification. All the best.

#include <string.h> //make sure that all necessary libraries are included & correct

#include <iostream>

#include <conio.h>

#include<math.h>

#define min 11 // Minimum number of villains

#define max 42 // Maximum number of villains

using namespace std;

int main() {

char name[30]; // Character buffer to store the name of the hero

int number; // Variable to store number of villains

long int new_number; // Variable to store new number of villains

// The variable is of type long to avoid overflow

srand(7); // Seeding random function with 7

cout << "What is your name?" << endl; // Asking for the name of Hero

gets(name); // Store the name in name array

cout << "Hello " << name << endl;// Acknowledging the hero

number = rand()%(max-min + 1) + min; // Calculating the villains to fight

cout << "There are "<< number <<" villains you need to defeat today"<< endl; // Printing results   

new_number = pow(number,3); // Raising the power of villain by 3

cout << "Oops! one of the villains was able to multiply himself by a power of 3. There are actually "<<new_number<< " villains." << endl;

// Print results

return 0;

// Return

}

Output. (Notice that as we're using ramdom function so exact output cannot be generated every time.)


Related Solutions

Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
C Code Edit this code to make it output all unique letters IN LOWERCASE of an...
C Code Edit this code to make it output all unique letters IN LOWERCASE of an input file. For example, with this input: Raspberry Grapefruit Straw berry raspBERRY Blue$$berry apple Pine_apple raspberry The output should be: raspberry grapefruit straw berry blue berry apple pine NOTE: Words with different capitlization, like raspberry and raspBERRY count as 1 unique word, so raspberry should only be seen once in the output. #include <stdio.h> #include <stdlib.h> int main() {     //Pointer to access the...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists,...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election (see note below) hold the names of the subdivision (see note below) hold the vote counts in the Aberdeen subdivision for each candidate hold the vote counts in the Brock subdivision for each candidate hold the vote counts in the Sahali subdivision for each candidate...
Using c# rewrite/edit the following program so that it runs the simulation 10,000 times (play the...
Using c# rewrite/edit the following program so that it runs the simulation 10,000 times (play the games 10,000 times) and count the number wins. Then calculate the winning probability by using the formula: the expected winning probability = the number of wins / 10,000 using System; class lottery { static void Main() { int n, random, choice = 1; Random randnum = new Random();    while (choice == 1) {    Console.Write("\nEnter a integer from 1 to 5:"); n =...
Write a program that calculates the mean, median and mode of a given array in the...
Write a program that calculates the mean, median and mode of a given array in the following manner: i) Write three functions mean (), median () and mode () that calculates the mean, median and mode of an array. ii) Using these functions write a program that calculates all the three above mentioned values for two different arrays A and B where A is an array that contains the number of hours spent by a person each day for playing...
1. What does the following program do? 2. What output does the program produce? 3. Examine...
1. What does the following program do? 2. What output does the program produce? 3. Examine the program code carefully. Is the program functioning correctly? 4. If you do not think the program is working correctly, describe why? 5. Include one screenshot of the program's output. C++ PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; void* myFunction(void* arg) { int actual_arg = *((int*) arg);    for(unsigned int i = 0; i < 10; ++i) { count++; std::cout << "Thread...
Take the following program and include overload functions into it. Display result of function. C++ Program:...
Take the following program and include overload functions into it. Display result of function. C++ Program: #include <iostream> using namespace std; // this is the additional function string read() {     string input;     cout << "Enter input: ";     cin >> input;     return input; } int main() {     // call function here     string output = read();     cout << "You entered: " << output; }
Write a C program that opens a file called "numbers.txt" in writing mode. The program should...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should then read floating point numbers from the keyboard, and write these lines to the opened file one per line, stopping when the number 0 is entered. Your program should check to make sure that the file was opened successfully, and terminate if it was not.
In the following Java program replace conditions in while loops to produce Christmas tree output. import...
In the following Java program replace conditions in while loops to produce Christmas tree output. import java.util.Scanner; public class Tree {     public static void main(String[] args)     {         int size;         Scanner scan = new Scanner(System.in);         System.out.print("Enter the size: ");         size = scan.nextInt();         int count = 0;         while (__________) //??? condition         {             int len = 0;             // print blanks             while (____________)//??? condition             {                 System.out.print(' ');                 len++;            ...
Write a  program in c++ using a map to create the following output. Here is the list...
Write a  program in c++ using a map to create the following output. Here is the list of students: 100: Tom Lee 101: Joe Jones 102: Kim Adams 103: Bob Thomas 104: Linda Lee Enter a student an ID to get a student's name: ID:  103 students[103] - Bob Thomas # of students: 5 Delete a student (Y or N)?  Y Enter ID of student to be deleted:  103 Here is the list of students after the delete: 100: Tom Lee 101: Joe Jones...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT