I need help with a C++ assignment:
Write a program containing the following:
1. Variable Definitions only as (DieRoll, Guess, cnt1, cnt2) followed by this statement:
srand((unsigned int)time (NULL));
which will give the random number generator a random starting point.
Note: srand and rand require the TIME.H (or iomanip)
cnt1 and cnt2 will be used in Chapter 5 drop box as counters for
loops. Do NOT create additional variables. Points will be taken off
for any additional variable creation.
2. Prompt the user for a whole number between 1 and
6.
3. Accept user input of the number – use Guess as the
variable
4. Simulate rolling a die with the following code (DieRoll variable
is defined in 1):
DieRoll = rand()%6+1; //Note: rand is a function
returning 0 thru 32767.
5. Display Guess and
DieRoll on the Screen with good user labeling
information. Additionally, display”WINNER” if
Guess and DieRoll are equal.
6. Display “DOUBLE WINNER” if DieRoll
is an odd number (use modulo). Not related to question 5
above.
7. If the DieRoll added to the Guess is greater than or equal 10
and DieRoll is even Display “YOU ARE A LUCKY
PERSON”. This is unrelated to the previous
requirements.
8. Create a for loop
to print the numbers 1 thru 5, all on the same line.
9. On the next output line create a for
loop which will count backwards by 1’s from 100 to
0 (inclusive of 100 and 0) only displaying every number which is
evenly divisible by 17.
10. Write a while loop to do the
same as 9.
11. Write a do…while loop to:
a. ask the user for a number ( use the variable
Guess).
b. get user input.
c. tell the user the remainder of dividing the
number by 5 (modulo) even if result is 0.
d. continue the loop until the user enters zero
(0) as the number. (Make sure the user is aware of this.)
Organize the loop like this (this is a planning technique called
pseudocode):
do
{
prompt the user for a # (a. above)
get user input (b. above)
output to user (c. above)
}while (your test goes here to see if the number is
0);
12. Create a for loop
within a for loop. The outer loop will count from 1 to 5.
The inner loop will count from 1 to 6 and write the product of the
outer loop counter multiplied by the inner loop counter, all on the
same line with one tab (‘\t’) between. Between the loop ends put a
line feed (endl or \n). The result should look like this:
1
2
3
4
5 6
2
4
6
8
10 12
3
6
9
12
15
18 etc,
Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface
#include<bits/stdc++.h>
using namespace std;
int main()
{
srand((unsigned int)time (NULL));
int Guess,DieRoll,cnt1,cnt2;
//Take user's input
cout<<"Enter a number from 1 to 6 : ";
cin>>Guess;
//generate random number
DieRoll = rand()%6+1;
//Display the numbers
cout<<"Your guess is "<<Guess<<" and Die shows
"<<DieRoll<<endl;
//check all given conditions
if(Guess==DieRoll)
cout<<"WINNER"<<endl;
if(DieRoll%2==1)
cout<<"DOUBLE WINNER"<<endl;
if(DieRoll+Guess>=10 && DieRoll%2==0)
cout<<"YOU ARE A LUCKY PERSON"<<endl;
//display 1 to 5 using for loop
for(cnt1=1;cnt1<=5;cnt1++)
cout<<cnt1<<" ";
cout<<endl;
//display 100 to 50 divisible by 17 using for loop
for(cnt1=100;cnt1>=0;cnt1--)
{
if(cnt1%17==0)
cout<<cnt1<<" ";
}
cout<<endl;
//display 100 to 50 divisible by 17 using while loop
cnt1=100;
while(cnt1>=0)
{
if(cnt1%17==0)
cout<<cnt1<<" ";
cnt1--;
}
cout<<endl;
do
{
cout<<"Enter any number(0 to exit) : ";
cin>>Guess;
cout<<Guess<<"%5 = "<<Guess%5<<endl;
}while(Guess!=0);
//display the required pattern
for(cnt1=1;cnt1<=5;cnt1++)
{
for(cnt2=1;cnt2<=6;cnt2++)
cout<<cnt1*cnt2<<"\t";
cout<<endl;
}
return 0;
}
Below is the screenshot of output
Hope i have answered your question satisfactorily.Leave doubts in
comment section if any.
I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions...
Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...
In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...
[Using Python] Create a program to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered. Your 5 questions should be a simple math problem, like "what is 5-4?" use a while loop based on the number of questions use a counter variable to count the number of questions asked e.g. questionCount +=1 user a counter variable to keep track of the correct...
Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...
I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...
In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...
need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive. The program then generates a random number using the random class: If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number, If the users guess matches the random number tell them they win! If the users guess does not match the random number tell them they are wrong. Use a...
Write a complete C++ program that do following. 1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0. 2) Create a size 10 array as counters for digits 0 - 9. 3) Use a while loop for processing a) Single out the current last digit using modular 10 technique b) Increment the corresponding counter through the index derived in a). 4) At the...
C++ Program - Arrays- Include the following header files in your program: string, iomanip, iostream Suggestion: code steps 1 thru 4 then test then add requirement 5, then test, then add 6, then test etc. Add comments to display assignment //step 1., //step 2. etc. This program is to have no programer created functions. Just do everything in main and make sure you comment each step. Create a program which has: 1. The following arrays created: a. an array...