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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
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