Hello everyone I'm new here! :icon_smile:
I'm also new to C++, and I'm having a little bit of trouble with a code of mine.
// function example
#include <iostream>
#include <string>
using namespace std;
int addition (int a, int b)
{
int r;
r=a+b;
return (r);
}
int main ()
{
string mystring2;
string mystr;
int z;
z = addition (5,3);
cout << "Please enter your name:";
cin >> mystr;
cout << "The result is " << z << mystr << "isn't that neat!";
cout << "I'm amazing, agreed?";
getline (cin, mystring2);
cout << mystring2 << "?!";
return 0;
}
In which the line:
getline (cin, mystring2);
Does not work.
I'm not sure what I'm doing wrong and I'm open to suggestions.
Additionally, when I change the code like this:
// function example
#include <iostream>
#include <string>
using namespace std;
int addition (int a, int b)
{
int r;
r=a+b;
return (r);
}
int main ()
{
string mystring2;
string mystr;
int z;
z = addition (5,3);
cout << "Please enter your name:";
cin >> mystr;
cout << "The result is " << z << " " << mystr << ", isn't that neat!";
cout << "I'm amazing, agreed?";
cin >> mystring2;
cout << mystring2 << "?!";
return 0;
}
It works fine.
I've been using this tutorial http://www.cplusplus.com/doc/tutorial/introduction.html perhaps someone can suggest a better one if this one isn't very good?