fork download
  1. // If you are not sure what some lines of code do, try looking back at
  2. // previous example programs, notes, or ask a question.
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. // Used for an if statement
  9. bool isNumGreat(int num);
  10.  
  11. int main() {
  12.  
  13. int number;
  14. char character;
  15.  
  16. cout << "Enter your favorite number: ";
  17.  
  18. cin >> number;
  19.  
  20. // This chain of if/else statements discovers if your number causes the isNumGreat function to return true,
  21. // or if your number is between 0 and 100, negative, or greater than 100
  22. if(isNumGreat(number)) {
  23.  
  24. cout << "Your favorite number is the answer to life, the universe, and everything!" << endl;
  25.  
  26. } else if (number >= 0 && number <= 100) {
  27.  
  28. cout << "Your favorite number is between 0 and 100!" << endl;
  29.  
  30. } else if (number < 0) {
  31.  
  32. cout << "Your favorite number is negative!" << endl;
  33.  
  34. } else {
  35.  
  36. cout << "Your favorite number is greater than 100!" << endl;
  37.  
  38. }
  39.  
  40. cout << endl << "Enter a letter a, b, c, d, e, or f: " << endl;
  41.  
  42. cin >> character;
  43.  
  44. // This switch statement detects if the letter is an 'a;' or a 'b,' 'c,' or 'd;' or an 'e;' or an 'f.' If you enter an
  45. // 'e' you will get the result from 'e' and 'f.' Finally, it can also default to a statement if you did
  46. // not enter any of those letters.
  47. switch(character) {
  48. case 'a':
  49. cout << "The next letter is 'b'" << endl;
  50. break;
  51.  
  52. case 'b':
  53. case 'c':
  54. case 'd':
  55. cout << "Your letter is boring." << endl;
  56. break;
  57.  
  58. case 'e':
  59. cout << "eeeeeeeeee" << endl;
  60.  
  61. case 'f':
  62. cout << "ffffffffff" << endl;
  63. break;
  64.  
  65. default:
  66. cout << "You didn't enter one of those letters! D:" << endl;
  67. }
  68. }
  69.  
  70. bool isNumGreat(int num) {
  71. // num == 42 is a boolean statement, so the function can return the result of it.
  72. return num == 42;
  73. }
  74.  
Success #stdin #stdout 0s 3416KB
stdin
42
f
stdout
Enter your favorite number: Your favorite number is the answer to life, the universe, and everything!

Enter a letter a, b, c, d, e, or f: 
ffffffffff