Modify the C++ program that you entered in Programming Project 1. Change the multiplication sign * in your C++ program to an addition sign +.
Recompile and run the changed program. Notice that the program compiles and runs perfectly fine, but the output is incorrect. That is because this modification is a logic error.
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 message, Hello
//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 part by using division symbole
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:100
Enter the number of peas in a pod:250
If you have 100 pea pods and 250 peas in each pod, then you have 350 peas in all the pods.