Question

Please note this is a question for my midterm so answer seriously and make sure it...

Please note this is a question for my midterm so answer seriously and make sure it works because i will be entering the code and debuging and write program with visual studio c ++ not java c++ please and thank you.

Your program should have a main function and include the necessary files using #include and use proper using notation as done in class. The program must use at least one if not more functions to do the following:

Write a program that

(i) randomly generates a two digit integer in the range 10 to 99). (10)

(ii) the program must display the generated random number and state whether the two individual digits of the number are the same or not. (10)

(iii) Provide sample runs of the program showing the print out when the digits are the same and when they are not. (5)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Here is the code for your assignment. I have added comments in the code for your reference.

The output and screenshot are at the end of this answer.

If you have any questions or need clarifications, leave me a comment.

If this answer helps you with your assignment, spare a moment and upvote this answer.


//File: randnos.cpp

#include <iostream>
#include <cstdlib>

using namespace std;

const int MIN_NUM = 10;
const int MAX_NUM = 99;

//Function returns a random number between 10 and 99
int getRandom() {
return MIN_NUM + (rand() % static_cast<int>(MAX_NUM - MIN_NUM + 1));
}

//function compares the random nos
bool compareNum() {
int randNum1 = getRandom(); //a
int randNum2 = getRandom();

cout << "Generated Random numbers are: " << randNum1 << " & " << randNum2 << ". ";
if(randNum1 == randNum2) { //b
cout << "Values are same" << endl;
return true;
} else {
cout << "Values are not same" << endl;
return false;
}
}

int main() {
  
compareNum();

//sample runs - when the numbers are different and when they are same
while( !compareNum()) { //c
}
}

//Output

g++ randnos.cpp && ./a.exe

Add a comment
Know the answer?
Add Answer to:
Please note this is a question for my midterm so answer seriously and make sure it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

    Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you. Pointers and Dynamic Memory – Chapter 11 1. Write code using pointers and the Accounts class from week 1 assignment as follows – create a program in which you a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation b. Add an initial balance of...

  • JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with...

    JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with individual digits from 0 to 9 inclusive. (i.e. 12345, 09382, 33044, etc.) The player then tries to guess the number. With each guess the program displays two numbers, the first is the number of correct digits that are in the proper position and the second number is the sum of the correct digits. When the user enters the correct five-digit number the program returns...

  • please put the comment each line, make sure i will have output too. write a program,...

    please put the comment each line, make sure i will have output too. write a program, Summarize (Summarize.java), containing the main() method, that first writes 10,000 random positive double type numbers, to the full accuracy of the number (15/16 decimal places), to a text file named DataValues.txt, one number per line. The program must then close that file, and reopen it for reading. Read back the values from the file and write the following information to a file named Summary.txt:...

  • I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm...

    I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm and write the program in java for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 13720, and the user guesses 83521, the...

  • PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from...

    PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods....

  • MAKE SURE TO INCLUDE WHAT PORTION OF THE CODE GOES IN WHAT FILE FOR THE CLASS....

    MAKE SURE TO INCLUDE WHAT PORTION OF THE CODE GOES IN WHAT FILE FOR THE CLASS. AND A PARAGRAPH DESCRIPTION OF THE CODE AND HOW IT WORKS!!! Please include all the steps and ill give you a great rating! An array can be used to store large integersone digit at a time. For example, the integer 1234 could be stored in the array a by settinga0 t, a1] to 2, a[2] to 3, and a[3] to 4. How-ever, for this...

  • Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program...

    Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...

  • Please make it sure your answers are meet what question needs with details I do not accept (copy ...

    Please make it sure your answers are meet what question needs with details I do not accept (copy / post) Using NetBeans IDE and write a CLI application that uses the BufferedWriter to write data to the file named "CustomerList.txt". =========================================================================== The application should follow this information A. Create a program that allows a user to input customer records (ID number, first name, last name, and balance owed) and save each record to a file. Save the program asWriteCustomerList.java.When you...

  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

  • Assignment 10 Assignments Guidelines This assignment has ONE question. Make sure you answer it an...

    IN Visual Basic please share also Desiger.vb Assignment 10 Assignments Guidelines This assignment has ONE question. Make sure you answer it and include comments. You will lose-10% ofyour grade in this assignment if the comments are missing Bill Calculator You need to design an application that user can enter his/her name, select their level: graduate vs. undergraduate, then they would enter the bill amount. See picture belovw Bill Calculator Please enter your Full name O Graduate Student Undergraduate Student Total...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT