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

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Age Range Value
AI Thread 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].
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top