Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 1, Problem 1P

Using your text editor, enter (that is, type in) the C++ program shown in Display 1.8. Be certain to type the first line exactly as shown in Display 1.8. In particular, be sure that the first line begins at the left-hand end of the line with no space before or after the # symbol. Compile and run the program. If the compiler gives you an error message, correct the program and recompile the program. Do this until the compiler gives no error messages. Then run your program.

Expert Solution & Answer
Check Mark
Program Plan Intro

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 Answer

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;

}

Sample Output

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
please 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++ please
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 identical
Use C++ Please provide screenshot of code. please include every detail and a code that can be copied and pasted. Thank you! This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin. Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later. You need to display output for all of the values between the starting and ending values. First two values are temperatures in Fahrenheit. You need to display all of the values from the first temperature to the last temperature. You increment from one temperature to the next by the increment value (the third value you read in). You need to convert these temperatures to Celsius and Kelvin. You need to output the temperatures as Fahrenheit, Celsius, and Kelvin. The numbers should be 18 characters wide with 4 digits of precision…

Chapter 1 Solutions

Problem Solving with C++ (10th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY