Hi, I have recently started using C++. I use g++ on Unix. I could not get a simple C++ program working.
The program is;
#include <iostream>
using namespace std;
int main()
{
double a, b;
cout << "enter your number";
cin >> a;
b = a + 1.15;
cout << b << endl;
return 0;
}
when I run this, I get;
$enter your number1.15
It does not get 'a' from the user. It assumes that 'a' is zero.
Where do I go wrong?
I pasted your program to run it on Linux g++ and it worked fine.
Hi, thanks!
What is the problem with g++ on Unix then?
vovan
4
Hi try to put endl after "cout << "enter your number"; "
#include <iostream>
using namespace std;
int main()
{
double a, b;
cout << "enter your number"<<endl;
cin >> a;
b = a + 1.15;
cout << b << endl;
return 0;
}
better control of the input is achieved by using getline...
cout<<"Please type something:"<<endl;
string line;
getline\(cin,line\);
cout<<"You entered:"<<line<<endl;