Assigning a Boolean Value Based on Age Range

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Age Range Value
Click For Summary
SUMMARY

The discussion focuses on assigning a Boolean value to the variable isTeenager based on the age range of a variable kidAge, specifically when kidAge is between 13 and 19 inclusive. Participants confirmed that the condition to check is kidAge > 12 && kidAge < 20. This condition can be directly assigned to isTeenager within an if statement to determine if the output should indicate "Teen" or "Not teen". The sample C++ program provided illustrates this logic effectively.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with Boolean logic and conditional statements
  • Knowledge of variable assignment in C++
  • Understanding of relational operators in programming
NEXT STEPS
  • Learn about C++ conditional statements and their syntax
  • Explore Boolean expressions and their applications in programming
  • Study variable scope and lifetime in C++
  • Investigate debugging techniques for C++ programs
USEFUL FOR

Students preparing for programming tests, C++ beginners, and anyone looking to understand conditional logic in programming.

ineedhelpnow
Messages
649
Reaction score
0
Write code to assign true to isTeenager if kidAge is 13 to 19 inclusive.

Sample program:
Code:
#include <iostream>
using namespace std;

int main() {
   bool isTeenager = false;
   int kidAge = 0; 

   kidAge = 13; 
   <STUDENT CODE>

   if (isTeenager) {
      cout << "Teen" << endl;
   }
   else {
      cout << "Not teen" << endl;
   }

   return 0;
}

i did the problem weeks ago but i can't remember how. can someone help me? I am reviewing for my test so I am going over problems again.
 
Technology news on Phys.org
How can we check to see if [m]kidAge[/m] is greater than 12 while at the same time less than 20? What condition do we need to be true?
 
kidAge>12 && kidAge<20
 
ineedhelpnow said:
kidAge>12 && kidAge<20

Yes, now can you use this condition in an if statement, where the appropriate action is taken if the condition is true?
 
ineedhelpnow said:
kidAge>12 && kidAge<20
You can also assign this expression directly to [m]isTeenager[/m].
 

Similar threads

Replies
12
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K