Write a
I'm not sure, but I think you will find the answer in Chapter #N. That's a good question. If I were you, I would not worry about such things. That question has puzzled philosophers for centuries. I don't know. I'm just a machine. Think about it and the answer will come to you. I used to know the answer to that question, but I've forgotten it. The answer can be found in a secret place in the woods. |
These answers are stored in a file (one answer per line), and your program simply reads the next answer from the file and writes it out as the answer to the question. After your program has read the entire file, it simply closes the file, reopens the file, and starts down the list of answers again.
Whenever your program outputs the first answer, it should replace the two symbols #N with a number between 1 and 18 (including the possibility of 1 and 18). In order to choose a number between 1 and 18, your program should initialize a variable to 18 and decrease the variable’s value by 1 each time it outputs a number so that the chapter numbers count backward from 18 to 1. When the variable reaches the value 0, your program should change its value back to 18. Give the number 17 the name NUMBER_OF_CHAPTERS with a global named constant declaration using the const modifier.
(Hint: Use the function newLine defined in this chapter.)
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
C++ How to Program (10th Edition)
Starting Out with C++: Early Objects
- In this homework assignment, you are going to code a java program which uses random numbers to create a guessing game. This will give you practice with random numbers and loops while allowing you to explore and understand a little more Java code. You will also need to test out this program to ensure the correctness of the algorithm and code. You will need to develop test data that will represent all possible kinds of data that the user may enter. You are going to write a program that allows the user to play a simple guessing game in which your program thinks up an integer between 1 and 100 and allows the user to make guesses until the user gets it right. (The program also counts how many tries it took to get the correct number). For each incorrect guess you will tell the user whether the right answer is higher or lower. Your program is required to exactly reproduce the format and behavior of the log of execution. Program should output: (Sample user output written in bold) This program…arrow_forwardWrite a program that displays a simulated paycheck. The program should ask the user to enter the date, the payee’s name, and the amount of the check. It should then display a simulated check with the dollar amount spelled out, as shown here: Date: 12/24/2012 Pay to the Order of: John Phillips $1920.85 One thousand nine hundred twenty and 85 cents You may assume the amount is no greater than $10000. Be sure to format the numeric value of the check in fixed-point notation with two decimal places of precision. Be sure the decimal place always displays, even when the number is zero or has no fractional part. Use either C-strings or string class objects in this program.arrow_forwardJAVAarrow_forward
- Langauge is C.arrow_forward10-6. Addition: One common problem when prompting for numerical input occurs when people provide text instead of numbers. When you try to convert the input to an int, you’ll get a ValueError. Write a program that prompts for two numbers. Add them together and print the result. Catch the ValueError if either input value is not a number, and print a friendly error message. Test your program by entering two numbers and then by entering some text instead of a number. 10-7. Addition Calculator: Wrap your code from 10-6 in a while loop so the user can continue entering numbers even if they make a mistake and enter text instead of a number.arrow_forwardWrite a program that allows a player to play Rock, Paper, and Scissors against the computer. In this version, if there is a tie the computer wins. The user must beat the computer to win around.The player will provide their name and the number of rounds they want to play. They will begin by entering their name and the number of rounds they would like to play. For each round, the player will input a character to represent their play (‘R’ for rock, ‘P’ for paper, or ‘S’ for scissors). The program will randomly select its play and output whether the player won or lost. After all, rounds have been completed the program will output the match-winner. In the case that the player wins the match, it will output their percentage of wins otherwise it will output the percentage of losses. Use the following functions / descriptions for your code. You may (should) add more functions as you deem necessary, but you may not omit or modify the functionality described below (Don’t forget you will also…arrow_forward
- Write a program that prompts the user to enter a sequence of numbers until a -999 is entered. It will print the numbers the user entered, five number in a row,with a before the first number and after the last number in each row. For example, Enter a number (-999 to stop): 23Enter a number (-999 to stop): 15Enter a number (-999 to stop): 1Enter a number (-999 to stop): 7Enter a number (-999 to stop): 9Enter a number (-999 to stop): 21Enter a number (-999 to stop): 17Enter a number (-999 to stop): 33Enter a number (-999 to stop): -999[23 15.17 9] [21 17 33]arrow_forwardWrite a python program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random number in the range of 1 through 3 is generated.If the number is 1, then the computer has chosen rock. If the muraber is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors.(Don't display the computer's choice yet.) The user enters his or her choice of "rock," "paper," or "scissors" at the keyboard. The computer's choice is displayed. A winner is selected according to the following rules: If one player chooses rock and the other player chooses scissors, then rock wins.(Rock smashes scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins.(Scissors cuts paper.) If one player chooses paper and the other player chooses rock, then paper wins.(Paper wraps rock.) If both players make the same choice, the game must be played again to…arrow_forwardPart 1: Complete the survey. Part 2: Peek-a-boo is a fun game that little kids like to play. To simulate this game on the computer, write a program that will generate a random number between 1 and 4. Then, will print to the screen the animal name associated to that number. The animal names used will be: pig when a 1 is generated cow when a 2 is generated chicken when a 3 is generated horse when a 4 is generated If your program generates a 3, the output will be: chicken The player will then enter a 1 if they would like to play again or anything else to exit the program. If the player enters "1 1 1 0", the output will be: horse chicken cow horse For coding simplicity, follow each output animal by a space, even the last one. Hint: To make testing easier, seed your random number generator with 0.arrow_forward
- Lab Activity: In python.arrow_forwardIn this assignment you will write a program that shows the valid moves of chess pieces. Your program will draw a board with 64 squares using the traditional layout, next ask the user to choose a move, and then, depending on the user's choice, redraw the board with the selected chess piece and its valid moves. Please see the examples of valid moves of chess pieces and the traditional chess board layout below:arrow_forwardIn the Raptor program Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the computer’s choice yet.)2. The user enters his or her choice of “rock,” “paper,” or “scissors” at the keyboard.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)• If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.)• If both players make the same choice, the…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,