#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
bool isAlive(true);
int hp(100);
cin >> hp;
if (hp ==0)
{
isAlive == false;
}
else
{
isAlive == true;
}
if (isAlive)
{
cout << "cool you are alive" << endl;
}
else
{
cout << "rip" << endl;
}
return 0;
}
#include <iostream>
int main()
{
int hp; // default initialize hp, don't give it any value
std::cin >> hp;
if (hp) // Tests to see if hp is true (0 is false, any number other than 0 is true)
std::cout << "cool you are alive" << std::endl; // hp is any number other than 0
else
std::cout << "rip" << std::endl; // hp is 0
return 0;
}
#include <iostream>
int main()
{
int hp; // default initialize hp, don't give it any value
std::cin >> hp;
// Using the conditional operator (aka the ternary, ?, operator) to test help and count the selected message
std::cout << ((hp == 0) ? "You are dead" : (hp > 0 && hp <= 30) ? "You are just barely alive!" :
(hp > 30 && hp <= 60) ? "You're alive!" : "You're alive and well!") << std::endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
bool isAlive = true;
int health = 100;
cout << "Enter the amount of health.\n";
cin >> health;
// if health is less than or equal to 0 then set isAlive to false
if(health <= 0)
isAlive = false;
// if isAlive is false than display R.I.P.
if(!isAlive)
cout << "R.I.P.\n";
// if isAlive is true than display....
else
cout << "Cool, you're alive.\n";
cin.get(); // so program doesn't automatically close
return 0;
}