Change Multiplication to Addition
Problem Description:
The purpose of this exercise is to create a program that has an error in it. To create the error change the "*" in the line that calculates total_peas to a "+". The program will still run but it will produce the wrong answer.
#include <iostream>
using namespace std;
int main( )
{
int number_of_pods, peas_per_pod, total_peas;
cout << "YOUR NAME\n";
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
cout << "If you have ";
cout << number_of_pods;
cout << " pea pods\n";
cout << "and ";
cout << peas_per_pod;
cout << " peas in each pod, then\n";
cout << "you have ";
cout << total_peas;
cout << " peas in all the pods.\n";
return 0;
}
Example Output:
Glenn Mayer
Press return after entering a number.
Enter the number of pods:
6
Enter the number of peas in a pod:
5
If you have 6 pea pods
and 5 peas in each pod, then
you have 11 peas in all the pods.
Required Test Cases:
2, 2
5, 7
Skills:
●Var ●Con I/O ○Format ○Logic ○Loops ○Functions ○Call by Ref ○File I/O ○Arrays ○Strings ○GM
|