Lab 4c.cpp - #include<cstdlib>#include<ctime>...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// C++ Program Test.cpp // Course CSE1311 Section // Assignment #: Lab 4 (Part c) // Due Date: February 18, 2016 // Purpose: /* Using a do-while loop structure to accomplish this task. The computer generate a random number between one and ten inclusive [1, 10]. The user allowe to guess at the number. After each guess, the computer tell the user whether his/her guess was too high or too low. Then it prints out the result until he/she guesses the correct number.*/ #include <iostream>
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <cstdlib> #include <ctime> using namespace std; int main() { std::srand(std::time(0)); int lower, upper, guess; int random_number = (rand()%10) +1; do { std::cout << "Guess what number I have: "; std::cin >> guess; if (guess > random_number) std::cout << "Your guess is too high\n"; else if (guess < random_number) std::cout << "Your guess is too low\n"; else std::cout << "You got it!\n\n"; } while (guess != random_number); system("PAUSE"); return 0; }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern