I am totaly new to C++, and i am trying to get sum of two digits, but i am getting some error, will somebody please correct my code.
Regards
I am totaly new to C++, and i am trying to get sum of two digits, but i am getting some error, will somebody please correct my code.
Regards
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a,b,sum;
cout<<"enter first amount";
scanf ("%d", &a);
count<<"enter second amount";
cin>>b;
sum=a+b;
printf ("sum=%d", sum);
getch();
}
What error are you getting - compiler/runtime? I can see that scanf
might be an issue as you don't include <cstdio>
(I'm unclear if <conio.h>
does that for you). Also, you are mixing input mechanisms (cin
and scanf
) - it is best to pick one and be consistent.
Also, you posted a code snippet. You should not post questions like these as code snippets but as new questions.
Also in line 11:count<<"enter second amount";
It should becout << "enter second amount";
In addition to what the previous posters said, you may want to consider not using the identifier "sum" as a variable.
This should work (albeit untested):
#include <iostream>
using namespace std;
int main()
{
int a, b, s;
cout << "enter first amount";
cin >> a;
cout << "enter second amount";
cin >> b;
s = a + b;
cout << "sum = " << s;
std::cin.get();
return 0;
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.