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

Discussion Overview

The discussion revolves around writing code to assign a Boolean value based on an age range, specifically determining if a given age qualifies as a teenager (ages 13 to 19 inclusive). The scope includes programming concepts and conditional statements in C++.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant requests help with a coding problem related to assigning a Boolean value based on age.
  • Another participant asks how to check if the age is greater than 12 and less than 20, seeking clarification on the necessary condition.
  • A subsequent reply provides the condition as kidAge > 12 && kidAge < 20.
  • Another participant reiterates the condition and prompts for its use in an if statement to take appropriate action.
  • One participant suggests that the expression can be directly assigned to the isTeenager variable.

Areas of Agreement / Disagreement

Participants generally agree on the condition needed to determine if the age qualifies as that of a teenager, but there is no consensus on the implementation details or the final code structure.

Contextual Notes

There are no explicit limitations noted, but the discussion may depend on understanding conditional statements and the syntax of C++.

Who May Find This Useful

Individuals preparing for programming tests, particularly in C++, or those seeking to understand conditional logic in coding.

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