Bool question

how would I write a bool statement if I want to display a message if somebody divided their income by 10% or if they did not divide their income by 10%.

For example if the person did dive their income by 10% I would display a true message saying that they did this.

If the person didn't then I would display another message saying that they did not do this.

thanks!
closed account (Lv0f92yv)
I suppose it might depend on how you were to determine this.

How is the person able to divide their income?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cout << "Enter your income: ";
cin >> income;
cout << "\nDo you want to divide by 10%?\n";
cin >> choice; //0 for no, 1 for yes?
if ( func(choice) )
cout << "They divided by 10%!\n";
else cout << "They didn't...\n"

bool func( choice )
{
   if ( choice == 1 )
      return true;

      else return false;
}


Something like this is simple, and probably not practical.

Maybe a more complete explanation of what you're trying to do would help.
Ok this is my assignment (yes I go to a church school). I'm not sure how to write a bool statement or formula on how to display


Income: 100
Tithe: 91
You are a full tithe payer.



Income: 532
Tithe: 40
Will a man rob God? Yet ye have robbed me.


the numbers are just what the user inputs.

#include <iostream>
using namespace std;

/*****************************************************
*
*****************************************************/
bool isFullTithePayer(float income, float tithe)
{
// your code goes here



return true;
}


/**********************************************************************
* Main will call isFullTithePayer() and display an appropriate message
* to the user based on the results
***********************************************************************/
int main()
{
float income;
float tithe;

// prompt user for income
cout << "Income: ";
cin >> income;

// prompt user for tithe
cout << "Tithe: ";
cin >> tithe;

// give the user his tithing report
if (isFullTithePayer(income, tithe))
cout << "You are a full tithe payer.\n";
else
cout << "Will a man rob God? Yet ye have robbed me.\n"
<< "But ye say, Wherein have we robbed thee?\n"
<< "In tithes and offerings. Malachi 3:8\n";

return 0;
If the tithe amount entered is less than 10 percent of the income.

Convert that expression to a math equation.
So would the format be:

if (tithe < 10% income)

sorry I really have no clue how to do bool.
A boolean value is just something that says "yes" or "no".

So, x == 42 is a boolean expression. Either x equals 42 or it does not. Thus, you can say:
1
2
3
4
if (x == 42)
  cout << "You have the X nature.\n";
else
  cout << "Keep studying, young grasshopper.\n";


In the case of a tithe, simply divide by ten and see if the amount given is equal to or greater than the result. You have it almost right. Here it is:

if ((income / 10) <= tithe)

BTW. You can return a boolean value directly. For example, the following are identical:
1
2
if (x == 42) return true;
else         return false;
 
return (x == 42);

Hope this helps.
Thanks that helped a bunch! I understand bool much more than I did. Now, however, after I have enter in if ((income / 10 <= tithe) do I need to add an else statement? I ran the program and when I type in 532 and 40 it still says I am a full tithe payer which I wouldn't be.
Eh... Duoas' check checks if the person paid the tithe in full, not if it's too little... just in case you didn't know...

And an else statement might cut down on your code, but is not mandatory. You could use another if statement. Nah, use the else statement.

-Albatross
Haha I've been staring at the screen too long I didn't even realize that it was just if the person paid in full, got it fixed and passed test!

Thanks to all who helped I really learned a lot doing this!
Topic archived. No new replies allowed.