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
I need your help with the question attached, Your writing your program in C# . When writing or printing out the output of your code please use the format when writing your code and when you want to print out the data too     static void Main(string[] args)     {         int student_id;         int student_pass, highest_avgerage_id, student_fail;         student_pass = 0;         student_fail = 0;         highest_avgerage_id = 0;             Console.Write("Enter a student id (0 to quit): ");             student_id = Convert.ToInt32(Console.ReadLine());         Console.WriteLine("Number of student who are moving on: " + student_pass);         Console.WriteLine("Number of student who are not moving on:  " + student_fail);             if (student_id == 0)             {                 is_continue = false;                 break;             } This is the format I need any tutor working on this to use when they are solving the problem and writing the code in C# please. Please let me know if…
For the program below, assume that a point on a Cartesian plane comprises values representing x and y coordinates.  The distance between two points in a Cartesian plane can be calculated using the formula derived from d=√((x2-x1)²+(y2-y1)²). Write a C++ program that prompts a user to input two points on the Cartesian plane and works out the distance between them. Use  comments in your code, highlight how you have used the following concepts of C++ : class, object, constructors and destructors.
I need help with this please....im using C# with screenshots of the code and the output

Chapter 1 Solutions

Problem Solving with C++ (10th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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