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.
Modified program code:
//Header file
#include <iostream>
using namespace std;
//main function
int main( )
{
//Variable declaration
int number_of_pods, peas_per_pod, total_peas;
//Prompt the user to enter input
cout << "Press return after entering a number.";
cout << "Enter the number of pods:";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:";
cin >> peas_per_pod;
//Calculation
total_peas = number_of_pods * peas_per_pod;
//Display output
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods ";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then ";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods. ";
return 0;
}
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 pea pods and 15 peas in each pod, then you have 150 peas in all the pods.