Concept explainers
Using your text editor, enter (that is, type in) the C++
Creation of main method to compute a value and testing the formula
Program Plan:
- Define the main method.
- Declare variables for count of pods, count of peas and total peas.
- Display message to get count of pods.
- Store value for count of pods.
- Display message to get count of peas in pods.
- Store value for count of peas in pods.
- Compute value for total peas by multiplying both input values.
- Display the resultant value of total peas.
Program Description:
The following java program describes about creation of main method to implement a formula for computing value for total peas.
Explanation of Solution
Program:
//Include library
#include<iostream>
//Use namespace
using namespace std;
//Define main method
int main()
{
//Declare variables
int numberOfPods, peasPerPod, totalPeas;
//Define message
cout<<"Press return after entering a number"<<endl;
//Define message
cout<<"Enter the number of pods"<<endl;
//Store value
cin>>numberOfPods;
//Define message
cout<<"Enter the number of peas in a pod"<<endl;
//Store value
cin>>peasPerPod;
//Compute value
totalPeas = numberOfPods*peasPerPod;
//Define message
cout<<"If you have ";
//Define message
cout<<numberOfPods;
//Define message
cout<<" Peas pods"<<endl;
//Define message
cout<<"and ";
//Display message
cout<<peasPerPod;
//Define message
cout<<" Peas in each pod, then"<<endl;
//Define message
cout<<"You have ";
//Display value
cout<<totalPeas;
//Display message
cout<<" Peas in all the pods";
//Pause console window
system("pause");
//Return
return 0;
}
Press return after entering a number
Enter the number of pods
10
Enter the number of peas in a pod
15
If you have 10 Peas pods
and 15 Peas in each pod, then
You have 150 Peas in all the pods
Press any key to continue . . .
Want to see more full solutions like this?
Chapter 1 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Database Concepts (8th Edition)
Modern Database Management (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- C++ Programming It should align exactly like the screenshot, sample output. The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. A2. D3. B4. B5. C6. B7. A8. B9. C10.D11. A12. C13. D14. B15. D16. C17. C18. A19. D20. B Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, and the answers should be stored in another array. After the student’s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.…arrow_forwardFor C++ The first TODO is to gather the necessary input from the user to complete the story. Create the variables that you will need; be mindful of which data types to use! Remember that string input should use getline instead of just cin by itself. The second TODO is to display the story once again, but now with the values entered by the user. This is where you will use the variables you made previously. The third TODO is to seed the random number generator using the current system time. We will need this in order for the next section to work. The fourth TODO is to create a visual graph of the stock price fluctuating. You will need to use the setfill and setw stream manipulators to make this work. The stock price value determines how many of the symbols to display. Make sure to round the price to the nearest dollar so that the chart is as accurate as possible. There are five fluctuations that you need to model in your program: The stock price is multiplied by a random number between…arrow_forwardCreate a standard C++ program wherein it satisfies the following objectives 1.Create a menu. (Under the menu, it should display the following) *Testing *Information *Exit note: create a loop link between the menu and the program will only stop if the user chooses "exit". 2.I will provide the codes under the testing menu and it's up to you if you want to improve it a little further. 3. Under the information menu, the program will then ask the user for its name, address, age, and current relationship status, be creative and you can add small simple features to the program itself. Thanks a lot! Here's our first version program under the testing menu #include <iostream>using namespace std; int main() { bool hasFever; bool hasCough; bool breathingProblem; char input; cout << "WELCOME TO COVID-19 TRACKER \n \n" ; cout << "Does the patient have fever? (y/n) "; cin >> input; if (input == 'y' || input == 'Y') { hasFever =…arrow_forward
- Task 1: Get an integer type input from the user and compare it with a number “10”. If an input is greater than 10, print “The input number is greater than the provided number”. (write the program in C++ language)arrow_forwardDO NOT COPY AND PASTE THE ANSWER THAT CHEGG HAS FOR THIS QUESTION. I HAVE ASKED THIS QUESTION TWICE, AND BOTH TIMES THE "EXPERT" COPIED AND PASTED THE ANSWER FROM CHEGG. PLEASE ACTUALLY SOLVE THIS PROBLEM, OR I'LL JUST HAVE TO CANCEL MY BARTLEBY SUBSCRIPTION. C++ Question Hello, Please create the correct code for the attached picture. Please create the code based on the given requirements. Please make sure it is working, but please DON'T use the FLAG VARIABLE or any advanced functions. Thank you!arrow_forwardI need help to my project 2 programming C++. Please Project 2 is a continuation of Project 1. Modify the code from Project 1 in the following ways: Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code using the following rules: The length of the room cannot be less than 5 feet The width of the room cannot be less than 5 feet The user's menu selection for the amount of shade should be 1, 2, or 3. If the user's input is invalid, the program should display an appropriate error message and prompt the user to re-enter their input. The user must be given an unlimited amount of attempts to enter valid input. Step 3: Add code to have the program ask the user if they would like to enter…arrow_forward
- Please rewrite the C++ code below according to the instructions and criteria. Please replace the if statement according to the last criteria highligthed in bold. Thank you. Instructions; Replace as many conditional statements in the 12 Days Of Christmas song with one or more arrays. Criteria compilation - the program compiles without error the first switch statement - replace the first switch statement with an array the second switch statement - replace the second switch statement with an array the if statement - rewrite the inner for loop by replacing the if statement and other statements in the inner for loop with references to these arrays:int last[] {-1, 0, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};int first[] {-1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; Expert Answers: Step 1 I have stored the values that are printed by 1st switch case statement in an array a. Similarly I have stored the values that are printed by 2st switch case statement in an array b. Then I removed the switch…arrow_forwardThe file provided in the code editor to the right contains syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.arrow_forwardHomework Instructions: For each Exercise below, write your code in an IDE and run your code within the IDE as well. Once you have satisfied the Exercise requirements, paste your code below under the corresponding Exercise. Exercise 1 Write a C++ program that will check if a given number (provided by a user) is prime or . ● not. Using a Loop here (but what loop is ideal here?) If we are checking if something is true or false, shouldn't we use conditional statements?arrow_forward
- C++ Programming. I need to develop my original code. Please help me write a C++ code following this instructions: (Please write your own code, not copy other contents please) The company needs a more detailed report to be generated at the end of each shift. The sample screen output with the report is listed below: Welcome to CTC Taxi. Do you need a taxi? Y Taxi CTC0001 will pick you up in a few minutes. (Taxi CTC0001 determined that there were 3 passengers) Do you need a taxi? Y Taxi CTC0004 will pick you up in a few minutes. (Taxi CTC0004 determined that there were 5 passengers) …… …… Do you need a taxi? N CTC Taxi served a total of 124 passengers today. CTC0001 CTC00022 CTC0003 CTC0004 CTC0005 CTC0006 19 Calls 25 Calls 10 Calls 12 Calls 22 Calls 13 Calls 25 Passengers 45 Passengers 34 Passengers 29 Passengers 24 Passengers 30…arrow_forwardplease help me complete the input operator and explain with comments. i am given a portion of the header file shown at the top of the image, just below the instructions. in c++ pleasearrow_forwardc++ You are working for a software firm that developped a word processor. A common error users often make is that they forget the caps locks on and print text like this: ”tHIS IS A SAMPLE of an error”, this usually happens at the beginning of a new sentence(i.e. right afer a dot or in a new line). Write a program to detect this error and fix it. The input will be a long string on keyboard.arrow_forward
- 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