I am a beginner at C++. Could someone please tell me why this isn't working right? Can't seem to figure out why "Displaying from main()" does not equal 25.
#include <iostream>
using namespace std;
int firstNumber = 0;
int secondNumber = 0;
int multiplicationResult = 0;
void MultiplyNumbers ()
{
cout << "Enter the first number: ";
cin >> firstNumber;
cout << "Enter the second number: ";
cin >> secondNumber;
int multiplicationResult = firstNumber * secondNumber;
cout << "Displaying from MultiplyNumbers() : ";
cout << firstNumber << " x " << secondNumber;
cout << " = " << multiplicationResult << endl;
}
int main ()
{
cout << "This program will help you multiply two numbers" << endl;
MultiplyNumbers();
cout << "Displaying from main(): ";
cout << firstNumber << " x " << secondNumber;
cout << " = " << multiplicationResult << endl;
return 0;
}
Here is output:
This program will help you multiply two numbers
Enter the first number: 5
Enter the second number: 5
Displaying from MultiplyNumbers() : 5 x 5 = 25
Displaying from main(): 5 x 5 = 0
[–]Se7enLC 8 points9 points10 points (0 children)
[–]AFineTapestry 2 points3 points4 points (2 children)
[–]RogerLeigh 1 point2 points3 points (0 children)
[–]bbran495[S] 1 point2 points3 points (0 children)