Hey, i have read your book and in if chapter at Practice problems
1. Ask the user for two users’ ages, and indicate who is older; behave differently if both are over 100.
I have a problem with my code below, can you help me please?
Code:
#include <iostream>
using namespace std;
int main()
{
int first_user_age;
int second_user_age;
cout << "Insert your first age" << '\n';
getline (cin, first_user_age, '\n');
cout << "Insert your second age/your friend age" << '\n';
getline (cin, second_user_age, '\n');
bool is_user_user_age_more_than_100 = first_user_age && second_user_age > 100;
if (is_user_user_age_more_than_100)
{
if (first_user_age > second_user_age)
{
cout >> "User age is more than 100 year and the first user is older than the second user" \n;
}
if (first_user_age < second_user_age)
{
cout >> "User age is more than 100 year and the second user is older than the first user" \n;
}
}
bool is_user_user_age_less_than_100 = first_user_age && second_user_age < 100;
if (is_user_user_age_less_than_100)
{
if (first_user_age > second_user_age)
{
cout >> "User age is less than 100 year and the first user is older than the second user" \n;
}
if (first_user_age < second_user_age)
{
cout >> "User age is more than 100 year and the second user is older than the first user" \n;
}
}
return 0;
}
Why is integer cannot combined with getline ?
I got this message "[Error] C:\Users\Guest\Documents\C-Free\Projects\program\main.cpp:10: error: no matching function for call to `getline(std::istream&, int&, char)'
Likewise the second problem i'm using integer
2. Implement a simple “password” system that takes a password in the form of a number. Make it so that either of two numbers is valid, but use only one if statement to do the check.
if we using string in problem 2 we could get an character besides number