Excuse my english. I am trying to write a code that a computer will ask me to type my first name and last name then after that the computer will ask me again to print my whole name using getline() and after printing my whole name it will print the programming arithmethic. Thank you
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int x;
string full;
string first;
string last;
cout << "First name: "; // prints first name
cin >> first;
cout << "Last name: "; // prints last name
cin >> last;
cout << "Your name is: " << first + " " + last << endl;
cout << "Enter your full name: ";
getline(cin, full); // prints whole line
cout << "Your whole name is: " << full << endl;
// prints arithmethic
int a = 45;
int s = 56;
x = a + s;
cout << "a + s = " << a + s << endl;
cout << "a + s = " << a - s << endl;
cout << "a + s = " << a * s << endl;
cout << "a + s = " << a / s << endl;
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int x;
string full;
string first;
string last;
cout << "First name: "; // prints first name
cin >> first;
cout << "Last name: "; // prints last name
cin >> last;
cout << "Your name is: " << first + " " + last << endl;
cin.ignore();
cout << "Enter your full name: ";
getline(cin, full); // prints whole line
cout << "Your whole name is: " << full << endl;
// prints arithmethic
int a = 45;
int s = 56;
x = a + s;
cout << "a + s = " << x << endl;
cout << "a - s = " << a - s << endl;
cout << "a * s = " << a * s << endl;
cout << "a / s = " << a / s << endl;
cin.get(); //to pause the screen. press enter to continue.
return 0;
}
The last division problem results in zero, because integers won't show a decimal value. Good luck.