I am a beginner in C++ and trying to learn it. I have a problem with this program.

#include <iostream>
using namespace std;

int main ()
{
    int FirstNumber = 0 ; int SecondNumber = 0 ;

    cout << " This program will help you multiply two numbers " << endl;
    cout << "Enter the First Number: " ;
    cin >> FirstNumber;

    cout << "Enter the Second Number: ";
    cin >> SecondNumber;

    int Result = FirstNumber * SecondNumber;
    cout << FirstNumber << " x " << SecondNumber ;
    cout << Result << endl;
    return 0;
}

Even though I typed cout to show the end result. It only shows until "FirstNumber" x "SecondNumber". What am I doing wrong?

Output was:

This program will help you multiply two numbers
Enter the First Number: 3
Enter the Second Number: 4
3 x 412

Works fine for me. Whatever the problem is, it's not the code.

You need to put quotes around FirstNumber and no quotes around variable names. Also put spaces where necessary so that FirstNumber and the value of x do not run together.

cout << "FirstNumber " << x << " SecondNumber " ;

AncientDragon, I tried that and it gives me an error. I am using visual studio 2010.

Here is the original code:

1: #include <iostream>
2: using namespace std;
3:
4: int main ()
5: {
6: cout << “This program will help you multiply two numbers” << endl;
7:
8: cout << “Enter the first number: “;
9: int FirstNumber = 0;
10: cin >> FirstNumber;
11:
12: cout << “Enter the second number: “;
13: int SecondNumber = 0;
14: cin >> SecondNumber;
15:
16: // Multiply two numbers, store result in a variable
17: int MultiplicationResult = FirstNumber * SecondNumber;
18:
19: // Display result
20: cout << FirstNumber << “ x “ << SecondNumber;
21: cout << “ = “ << MultiplicationResult << endl;
22:
23: return 0;
24: }

I tried to make my example from it. Everything goes well but mine doesn't shows the end result.

Edit: When I made it like this it worked;

cout << " = " << Result << endl;

I thought the cout is supposed to show the "Result" whatsoever. Why did it showed the result only after I added "=" ?

I figured it out.

int Result = FirstNumber * SecondNumber;
    cout << FirstNumber << " x " << SecondNumber << endl ;
    cout << Result << endl;

It shows the end result. I had to put add "endl" at the end of 2nd line.

int n1,n2, result;
cout<<"enter first number"<<endl;
cin>>n1;
cout<<"ente second number"<<endl;
cin>>n2;
result=n1+n2;
cout<<"the result is ="<<result<<endl;
#include <iostream>
#include <conio>
   int a,b,c;
   main()



{

   cout<<"Enter 1st number\n";cin>>a;//input from user first number
   cout<<"Enter 2nd number\n";cin>>b;//input from user 2nd number

  c=a*b;//compute the multipication of 2 numbers

  cout<<"Multiplication of 2 number is=\t"<<a<<"x"<<b<<"="<<c<<endl;//result of 2 number is showed as

   }
   This program Broland c++
   thanks for reading....................send me your question about c++ ..
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.