C/C++ Assigning a Boolean Value Based on Age Range

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Age Range Value
Click For Summary
To determine if a variable `isTeenager` should be set to true based on the value of `kidAge`, the condition to check is whether `kidAge` is between 13 and 19, inclusive. This can be expressed as `kidAge >= 13 && kidAge <= 19`. In the provided sample program, the variable `isTeenager` can be assigned the result of this condition directly. The code can be modified to include an if statement that checks this condition, allowing the program to output "Teen" if `isTeenager` is true, or "Not teen" if it is false. This approach effectively checks the age range and assigns the boolean value accordingly.
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].
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 15 ·
Replies
15
Views
4K
Replies
12
Views
3K
Replies
3
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
10K