Need help writing small program

closed account (iNyqM4Gy)
This deals with bools
Create a program that asks the user for their age. The program then outputs 1 if the age is 21+ (and outputs 0 if its under 21).
So, for example if the user enters 14, the program would output 0.
If the user entered 45, the program would output 1.
Last edited on
Nice try, we won't help you with your homework.

Why don't you start by writing pseudo code? Try to convert that into C/C++ and if you run into any problems we'll help. Use the code tags to post your code.
Last edited on
closed account (iNyqM4Gy)
I have no clue how to make it greater than 21 and less than 21. Can you tell me how in c++?
Last edited on
Are you learning from an online electronic course or are you attending real classes?

Read about if...else and then visit this page: http://www.cplusplus.com/doc/tutorial/operators/
Don't forget to read about if...else first.

Write a short program, and post it here.
Last edited on
closed account (iNyqM4Gy)
Can you give me a hint on 21+? I read through the page but can't figure it out..
Well how would you write it in pseudo code or just plain mathematics?


if age >= 21 then
        do this thing
otherwise
        do this other stuff
end if


It's simple really. I'm sure you can convert this into C/C++ code and work with it.
This link has examples you can work with: http://www.cplusplus.com/doc/tutorial/control/
Last edited on
closed account (iNyqM4Gy)
I haven't learned if or then while.....we can't use that. I'm just starting basic bools. You really aren't helping me..
Last edited on
Well then you shouldn't be writing this program if you have learned neither operators (==, >=, <=) nor if and else.

Your teacher must be testing to see how much you can explore by yourself, because programming is all about exploring things you don't know.

You won't get any help if you don't want to learn. I won't give you straight up C/C++ code. Maybe someone else will.
I haven't learned if or then while.....we can't use that. I'm just starting basic bools.

A boolean type has a true/false (yes or no) value. It serves no purpose at all until that value is tested. You would test the value in statements such as if, or while etc.

Without such tests, what you have is the equivalent of "the sound of one hand clapping", you can meditate upon it, but it won't be a program.
hey pav500 i think you are in my class and our professor strictly taught us this. maybe you weren't paying attention in class. that's not nice. it's in our lecture notes, schaum's outline, and his powerpoint slides which you can print out. has all the info there. i know that you are in my class because our professor is unique and he creates his own questions, so you have to be in our class to be with this unique question.
Last edited on
Topic archived. No new replies allowed.