C++ : Input age of a person and print a message accordingly


SUBMITTED BY: Guest

DATE: Oct. 14, 2013, 3:52 p.m.

FORMAT: C++

SIZE: 942 Bytes

HITS: 1063

  1. // Program Purpose: Input age of a person and print a message accordingly
  2. #include <stdio.h>
  3. int main()
  4. {
  5. int age;
  6. printf("\n Please enter your age : ");
  7. scanf_s("%d", &age);
  8. if (age >= 16)
  9. {
  10. printf("\n You can get a driver's license.");
  11. if (age >= 18)
  12. {
  13. printf("\n You can buy tobacco products, join the military, and legally vote.");
  14. if (age >= 21)
  15. {
  16. printf("\n You can buy alcohol and legally gamble.");
  17. if (age >= 25)
  18. {
  19. printf("\n You can get lower car insurance rates and become a US congressman.");
  20. if (age >= 30)
  21. {
  22. printf("\n You can become a senator.");
  23. }
  24. }
  25. }
  26. }
  27. else
  28. {
  29. printf("\n Stay at home, kid!");
  30. }
  31. }
  32. getchar();
  33. getchar();
  34. return 0;
  35. }

comments powered by Disqus