Advertisement
HakdogForce

LABORATORY EXERCISE 1 - 02 ONE DIMENTIONAL ARRAY

Dec 3rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. /*  ONE-DIMENSIONAL ARRAY
  2.     Porquillo, Aljan A.
  3.    
  4.     LABORATORY EXERCISE 1 - 02
  5.     ONE DIMENTIONAL ARRAY
  6. */
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int scores = 0;
  12. char input;
  13.  
  14. char answers[] = {
  15.     'D', 'C', 'D', 'D', 'A',
  16.     'B', 'C', 'A', 'B', 'B',
  17.     'C', 'D', 'A', 'B', 'C',
  18.     'D', 'D', 'A', 'B', 'A',
  19.     'A', 'B', 'D', 'A', 'C'
  20. };
  21.  
  22. int main(){
  23.     for(int i = 0; sizeof(answers) > i; i++){
  24.         system("cls");
  25.     cout << "Question " << i+1 << endl;
  26.         cout << "Answer: ";
  27.         cin >> input;
  28.        
  29.         if(input == answers[i]){
  30.             scores++;
  31.         }
  32.        
  33.         cin.ignore();
  34.     }
  35.    
  36.     system("cls");
  37.     cout << "Total scores " << scores << " out of " << sizeof(answers) << endl;
  38.    
  39.     if(scores >=15){
  40.         cout << "Congrats! you have passed" << endl;
  41.     }
  42.     else{
  43.         cout << "Sorry! you failed" << endl;
  44.     }
  45.    
  46. }
  47.  
  48. /* PSEUDO CODE
  49.  
  50. set variable score to 0
  51. set variable char to input
  52.  
  53. set predefined array with answers
  54.  
  55. loop size of answers then increment
  56. display "Question up to 1 to 25"
  57. display "Answer"
  58. then user input answer to allocate in set variable "input"
  59.  
  60. condition if true inputed answers will correct in the save array
  61. increment
  62.  
  63. ignore to be input again
  64.  
  65. system clear
  66. display total scores out of 25 numbers
  67.  
  68. if score is greater or equal to 15
  69. display Passed!
  70.  
  71. else
  72. display Failed!
  73.  
  74. end program
  75.  
  76. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement