MarkSix.cpp - AST21105 Object Oriented Programming and Design Lab02 Part B Suggested Solution#include is a pre-processor command denoted by which tells

MarkSix.cpp - AST21105 Object Oriented Programming and...

This preview shows page 1 - 3 out of 3 pages.

// --------------------------------------------------- // // AST21105 Object Oriented Programming and Design // Lab02 Part B - Suggested Solution // // --------------------------------------------------- // #include is a pre-processor command denoted by #, // which tells the compiler to take iostream and ctime, // compile them into the program which is anothor file // that has the implementation of cin, cout and time function #include <iostream> #include <ctime> #include <limits> using namespace std; int main() { int generateNo[7]; int guessNo[7]; // Code for random numbers generation srand((unsigned int)time(NULL)); for(int i=0; i<7; i++) { do{ generateNo[i] = rand() % 49 + 1; bool isDistinct = true; for(int j=0; j<i; j++) { if(generateNo[i] == generateNo[j]) { isDistinct = false; break; } } }while(!isDistinct); } // Display randomly generated numbers cout << "[ Mark Six Simulation ]" << endl; cout << "Six regular numbers drawn are "; for(int i=0; i<6; i++) cout << generateNo[i] << " "; cout << endl; cout << "Extra number drawn is " << generateNo[6] << endl; cout << "---------------------------------------------------" << endl; // Code for user input bool valid; do{ valid = true; cout << "Enter guess numbers: "; for(int i=0; i<6; i++) cin >> guessNo[i]; for(int i=0; i<6; i++) { bool leave = false; if(guessNo[i] < 1 || guessNo[i] > 49) { valid = false; cout << "Out of range number found, please re-enter" <<
Image of page 1
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture