Professional Documents
Culture Documents
Code Modifying Part
Code Modifying Part
2. #include <iostream>
using namespace std;
int main()
{
int favoriteNumber, numberOfPods, peasPerPod, totalPeas;
cout << "If you have " << numberOfPods << " pea pods\n";
cout << "and " << peasPerPod << " peas in each pod, then\n";
cout << "you have " << totalPeas << " peas in all the pods.\n";
return 0;
}
3. #include <iostream>
using namespace std;
int main()
{
int favoriteNumber, numberOfPods, peasPerPod, totalPeas;
int firstNumber, secondNumber, sum;
cout << "If you have " << numberOfPods << " pea pods\n";
cout << "and " << peasPerPod << " peas in each pod, then\n";
cout << "you have " << totalPeas << " peas in all the pods.\n";
return 0;
}
4. #include <iostream>
using namespace std;
int main()
{
int favoriteNumber, numberOfPods, peasPerPod, totalPeas;
int firstNumber, secondNumber, result;
cout << "If you have " << numberOfPods << " pea pods\n";
cout << "and " << peasPerPod << " peas in each pod, then\n";
cout << "you have " << totalPeas << " peas in all the pods.\n";
return 0;
}
Scenarios:
1. Negative Number (e.g., -22):
If the user enters a negative number like -22 as the second input, the
subtraction operation will work correctly, and the result will be displayed
accordingly.
2. Extremely Large Number (e.g., 9,876,543,210):
C++ data types like int have limits on the range of values they can
represent. If the user enters a number like 9,876,543,210 and subtracts
another number from it, the result may overflow the range of int , leading
to unexpected behavior or incorrect results. In such cases, using a data
type like long long with a larger range might be more appropriate to
handle extremely large numbers.
5.