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...
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...
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 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...
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.
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...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
Your assignment is to build a program that can take a string as input and produce...
Your assignment is to build a program that can take a string as input and produce a “frequency list” of all of the words in the string (see the definition of a word below.) For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words. In the output, each line contains of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT