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++ (Looseleaf) - With Access
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)
- I have a problem with the program below. Line 31 give a warning of 3 dots (…) under the suf word suffix. I have attached a screenshot showing where the problem is and a message box stating what the problem is. If possible, can you fix this program problem please. Thank you Write a program in C++ that reads a sentence as input and converts each word to "Pig Latin." In one version, to convert a word to Pig Latin, your remove the first letter and place the letter at the end of the word. Then you append the string "ay" to the word. Here is an example: English: I SLEPT MOST OF THE NIGHT Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY Criteria program compiles2) program solves problem according to specification3) program declares, creates, or initializes static or dynamic array correctly4) if required program defines function or functions with array parameters or array returns5) program uses arrays to solve problem6) program destroys any dynamic arrays #include<iostream>…arrow_forwardWrite a C++ code for the following question as quickly as you can. But please do the same as asked in the Question...arrow_forwardFor this C++ Program, help me identify the following: A brief description of the code What is the purpose of the code Explain the codes and how it is used to execute the program CODE PROBLEM:Write a program that prompts the user to enter 10 names, each with a maximum of 30 characters. Output the names that start with the letter A and its corresponding length.arrow_forward
- The code box below shows a simple C++ program. The program declares and initializes three integers. Then it computes the average of these integers and displays the result. However, there are some mistakes in the code. Find and fix these mistakes such that the code will display the exact output below. Please note that the names of the variables and constants are the same as those in the code in the image and adhere to them accurately. The reason is that the program corrects the code automatically and it must be identicalarrow_forwardCorrect and detailed answer will be Upvoted else downvoted. Thank you! What will be the output of the following C++ code? #include <iostream>using namespace std;int main(){float f1 = 0.5;double f2 = 0.5;if (f1 == 0.5f)cout << "equal";elsecout << "not equal";return 0;}arrow_forwardHello, I am struggling with getting this DICE GAME to function properly. I have made an attempt to try and get the overall program to debug and run without errors, but to no avail. If I can get some help getting my PYTHON program to Run Correctly. #Lab 7-3 The Dice Game #add libraries needed playerTwo = 'NO NAME' playerOne = 'NO NAME' inputNames = ("enter name") import random #the main function def main(): print #initialize variables endProgram = "no" playerOne = "NO NAME" playerTwo = "NO NAME" #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while "endProgram" == 'no': #initialize variables p1number = 0 p2number = 0 winnerName = 'NO NAME' #call to rollDice winnerName = "rollDice"(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo displayInfo: ("winnerName") #end of while loop endProgram = "raw_input"('Do you want to end program?(Enter yes…arrow_forward
- Instructions In this chapter, you learned that although a double and a decimal both hold floating-point numbers, a double can hold a larger value. Write a C# program named DoubleDecimalTest that declares and displays two variables—a double and a decimal. Experiment by assigning the same constant value to each variable so that the assignment to the double is legal but the assignment to the decimal is not. In other words, when you leave the decimal assignment statement in the program, an error message should be generated that indicates the value is outside the range of the type decimal, but when you comment out the decimal assignment and its output statement, the program should compile correctly. Note: Leave the decimal assignment statement in the program on final submission to receive full credit.arrow_forwardI need help writing a program in C++ that prompts the user to input three numbers. The program should then output the numbers in ascending order, separated by a single space.arrow_forwardHi. Can you solve this question? Write a c program dist.c that calculates the distance between two points and prints the result on the screen. The cartesian coordinates of the points would be given in the command line as 6 parameters. Your program should check if the number of arguments provided is correct and that the six coordinates are valid numbers of type double dist.exe x1 y1 z1 x2 y2 z2 For example, to calculate the distance between the two points (0, 0, 0) and (1, 1, 1), the program would be run as: dist.exe0 0 0 1 1 1 and the screen output would be 1.73205arrow_forward
- These to two screenshots are ONE SINGLE assignment. If you cannot complete this assignment in full, do not answer this question. If, however, you do plan on building a program using C++ based on the instructions from these two screenshots, then please continue. Thank you for your understanding. When you are done, join all your programs together and present the user with a menu so they can select which one they want to run.arrow_forwardMY CODE WAS BELOW, Can you help me edit my code to provide the given output. Create a nested looping program in C-language that will produce the given output below (use any of the looping statements) ************************* --------------------------------------------------------------------------------- #include<stdio.h>#include<conio.h>#include<windows.h>void gotoxy(int x, int y){COORD pos ={x , y};SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}main(){ int x,y; for (y=1; y<=5; y++) { gotoxy(x,y); printf("*"); getch(); }}arrow_forwardI would like to create a C++ code that creates a table for the user's choice of basic math operations (+, -, *, /, and %). The operation should only use integers, so that there are only whole numbers being used. As an example, the program interaction might look something like this: $ ./mathtable.out Welcome to the Math Table Program!!! Table Menu 1) Addition table 2) Multiplication table 3) Subtraction table 4) Division table 5) Remainder table 6) Quit Choice: 3 What size should the subtraction table be? 30 I'm sorry, 30 is too large of a subtraction table to print on the screen... What size should the subtraction table be? -3 I'm sorry, -3 would be stupid... What size should the subtraction table be? 3 Thank you...calculating... - | 1 2 3 ----+----------- 1 | 0 -1 -2 2 | 1 0 -1 3 | 2 1 0 Table Menu 1) Addition table 2) Multiplication table 3) Subtraction table 4) Division table 5) Remainder table 6) Quit Choice: q Thank you for using the MTP!! Endeavor to have a…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning