Write code that uses any type of loop. The code should continually ask for a user input and sums all user inputs that are divisible by 2. The loop should continue until the user enters a negative number. The code should output the sum a single time once user entry has completed. You may assume all libraries and namespaces have been previously written into the code, you are just writing everything that would go inside the main function (beyond the return 0:).
Q: 6. Write a loop that calculates the total of the following series of numbers:
A: START DECLARE y = 30 DECLARE sum = 0 FOR x = 1 to 30 SET sum = sum + (x/y) DECREMENT y by 1 PRINT…
Q: Why is the following function an infinite loop even though Value is sometimes odd within the loop?…
A: The condition of a loop is checked after executing all the instructions written inside the loop. For…
Q: Consider the following loop statement. Assume that the execution of the Keyboard.readInt() statement…
A: Integer is a whole number including zero . like .....-4, -3 -2 -1 0 , 1, 2, 3, 4 ... So, the DO…
Q: i=5; do {int x=0; i++; }while (i<5;). The body of loop will execute how may times?
A: This code will not give output as it has a syntax error here. while(i<5;)
Q: import java.util.Scanner; /** * ii. - This program allows money to be input in one currency and…
A: Algorithm to convert one currency to another currency: Step1: Declare money, convertedMoney ,…
Q: Write a program in C++ that calculates the occupancy rate for a hotel. The program should start by…
A: Step 1 : Start Step 2 : Take User input for the Number of Floors in the hotel. Step 3 : If the Total…
Q: How many times does a for loop run? A. A for loop runs a random number of times. B. The value of the…
A: How many time the for loop runs . How is lines of code in function is executed. What happen when…
Q: Write a FUNCTION that asks the user to input a string. Unless the user inputs "END" or "end", a loop…
A: Summary: In this question, we will take a string from the user and again take a string from the user…
Q: Write a for loop that uses the loop variable j and that would efficiently display the first 12…
A: Since no programming language is mentioned, I am using python Algorithm: Start Iterate through the…
Q: When does the following while loop terminate? char ch = 'D'; while ('A' (static_cast (ch) + 1);
A: Given while loop: char ch = 'D';while ('A' <= ch && ch <= 'Z') ch =…
Q: 7. Write pseudo code that will calculate a running sum. A user will enter numbers that will be added…
A: //Read an integerN = INPUT()//Variable to store running sumRUNNING_SUM = 0//Check if number is…
Q: QUESTION 10 def cube (number): for i in range (number, number): for j in range (number) : print…
A: In place of FILL THIS PART just write number*number*number Hence the answer to be filled in the box…
Q: Is a repetition control structure that allows you to efficiently write a loop that needs to execute…
A: The correct option is first option which is for-loop.
Q: Write a for loop that calculates the total of the following series of numbers: 2 3 4 30 + 1 30 29 28…
A: The Loop is given below:
Q: 0) Write a program that calculates and returns the sum of 1 to n in steps of , where n is an…
A: #note no programming language is mentioned so i was used c++ programming #include <iostream>…
Q: USE JAVA Write an application that allows a user to enter the names and birthdates of up to 10…
A: Given: USE JAVA Write an application that allows a user to enter the names and birthdates of up to…
Q: Write another program that generates another table with the same columns and decimals but by using a…
A: Answer in step2
Q: Write a program to compute the sum of the first N Fibonacci numbers, where N is an integer that is…
A: Write a program to compute the sum of the first N Fibonacci numbers, where N is an integer that is…
Q: Write a do while loop that uses the loop control variable to take on the values 0 through 10. In…
A: 1- As per the assignment requirement, print the number 0 to 10 along with multiply value 2 and 10…
Q: 1. Using a loop of your choice, read information from the console about employees in a company. Each…
A: Program:
Q: 3. What loops needs a semi colon after? a) For loop b) While loop c) Do while loop d) All of the…
A: Semicolon is a legitimate statement called null statement * that means " do nothing". Statements are…
Q: In situations where we need to execute body of the loop before testing the condition, we should use…
A: There is one situation is given, where we have to use one type of loops available in programming.…
Q: Write a program with python using random module for a (very) rudimentary shooter "game". You are the…
A: Program Algorithm-START-Step1: Import the essential modulesStep2: Define the shoot function.Step3:…
Q: What is the difference between the while loop and the do-while loop?
A: Difference between the while loop and the do-while loop:
Q: Write a program in C++ that calculates the occupancy rate for a hotel. The program should start by…
A: the answer is given below:-
Q: #include #include using namespace std; const int X1_INDEX= 1; const int X2_INDEX= 0; const int…
A: C++ program to find the square roots of quadratic equation :- #include <iostream>#include…
Q: Write the following function to display three numbers in increasing order:def…
A: PROGRAM CODE: import java.util.Scanner; public class Main { public static void main(String[]…
Q: -Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is…
A: here in this question we have asked to write program which take input from user and calculate the…
Q: Write a program in C++ that calculates the occupancy rate for a hotel. The program should start by…
A: Code.... #include <iostream> using namespace std; int main() { int floors = -1; while…
Q: By using Loop in c++, you are responsible to develop a Credit Limit Calculator, which will determine…
A: Find Your Code Below
Q: 4- GIVE ME EXAMPLE FOR NESTED LOOP ?
A: NOTE: As per Bartleby, if there are multiple questions available then we are allowed to solve first…
Q: Case - I: Playing with Digits Write a program which reads input integers from input file which…
A: Required: Required code with comments for explanation and screenshot of both code and output has…
Q: A for loop can contain multiple initialization actions separated by commas. True False
A: For loop is an iterative approach to execute any part of code repetitively with condition applied in…
Q: Program52.java Write a program that prompts the user for a binary number (from 3 to 8 bits) as a…
A: by bartleby guidelines i am able to do only one question.
Q: Non dynamic arrays are allocated at runtime where dynamic arrays are allocated at compile time. True…
A: Question 3: False Question 4: True
Q: :* Write *3 code snippet each in python* that contains For loop, While loop and loop recursion. Copy…
A: Python provides different ways for executing the loops. While all the ways provide similar basic…
Q: Write a program that will tell a user if their number is prime or not. Your code will need to run in…
A: A number is said to be prime number if it has factors 1 and itself A number is said to be factor if…
Q: Subject) - jcofield122e x O Lab 6: Module 6 - Repetitic x…
A: Here since programming language not mentioned using C
Q: Write a FUNCTION that asks the user to input a string. Unless the user inputs "END" or "end", a loop…
A: To find the letters and numbers in the string, we need to check the each character for the alphabets…
Q: By using while loop OR do..while loop, write a program that displays a list of groceries. Then,…
A: PROGRAM CODE: //Include header files#include <iostream>#include<iomanip>using namespace…
Q: 1. Ask the user to input values for the first and second currency (e.g. USD for dollars, EUR for…
A: here we make simple java program to currency converter:…
Q: 1) Which programming structure is best suited to a. For loop b. While loop c. If.else d. Do while…
A: "Since you have posted a question with multiple subpart, we will solve the first three subpart for…
Q: Question 1: Write a program in JAVA that displays a menu as shown in the sample run and asks user to…
A: PROGRAM EXPLANATION: Import java.util package. Create the main class and the main method. Create a…
Q: Hello, I have an assignment in the python program. Professor gives me a text like this: January.txt…
A: Python program to generate the January Bank Statement. customer’s account number, beginning balance,…
Q: 12. Write a loop of the specified type that sums up the even integers between 1 and 21. a. a while…
A: ANSWER:-
Q: What will be the value of AH after executing the following code mov al, 0F3H mov ah, 0F3H mov…
A: mov al, 0F3H ----> This instruction done al = F3 H => al = ( 11110011 )2 mov ah, 0F3H…
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images
- 2- The factorial n! of a positive integer n is defined as n! = 1*2*3 . .. * (n-1) * n Where 0! = 1 Write a function to calculate the factorial of a number. Argument: A number n of type unsigned int. Returns: The factorial n! of type long double. Write two versions of the function, where the factorial is • calculated using a loop calculated recursively Test both functions by outputting the factorials of the numbers 0 to 20.Write a C++ program that simulates online shopping. Declare a variable cart to be an empty Array. The program should have a loop that continues as long as the user wants to shop. Each time through the loop read in the name, price, and quantity of the item the user wants to add to the cart. After adding an item to the cart, the cart contents should be printed. After the loop print a "Please pay ...” message with the total price of the items in the cart.2- Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is an argument passed to the function. For example, if 11 is passed, it will return 1 + 3 + 5 + 7+ 9 + 11. Do this using a for loop. Calling the function will look like this: >> sumsteps2 (11) ans = 36
- Add a function to get the CPI values from the user and validate that they are greater than 0. 1. Declare and implement a void function called getCPIValues that takes two float reference parameters for the old_cpi and new_cpi. 2. Move the code that reads in the old_cpi and new_cpi into this function. 3. Add a do-while loop that validates the input, making sure that the old_cpi and new_cpi are valid values. + if there is an input error, print "Error: CPI values must be greater than 0." and try to get data again. 4. Replace the code that was moved with a call to this new function. - Add an array to accumulate the computed inflation rates 1. Declare a constant called MAX_RATES and set it to 20. 2. Declare an array of double values having size MAX_RATES that will be used to accumulate the computed inflation rates. 3. Add code to main that inserts the computed inflation rate into the next position in the array. 4. Be careful to make sure the program does not overflow the array. - Add a…Abstracting Decisions and Validation. Like with calculations, any logical task in a program can be represented by a function. You will design a new version of the program you created below. This new version will define and use functions for validating the user input, and looking up the value that corresponds to that valid input. Your program shall: Define a function that returns a valid user input. This function will use a while loop to make sure the sure the user enters a valid value. Define a function that accepts the user input as a paramter, uses the decision structure of the program you created in program below to return the value associated to that input. Use a meaningful name for the functions above. Define a function main() to drive the functionality of the program as it is used throughout Chapter 6 of the textbook. Run and test the program to make sure it works correctly SummaryThe program calculate a waist measurement in inches, andprints the corresponding pant size.…Write a function to display a pattern as follows: **************** ************** ************... *The function header is void displayPattern(int n)
- In C++ Create an array of random 10 random numbers. Use the "range-based for loop" (sometimes called "enhanced for loop") to put the values into the array (users choice of number) and use the "range-based for loop" to output the numbers to the console.Using a Sentinel Value to Control a while Loop Summary In this lab, you write a while loop that uses a sentinel value to control a loop in a Java program that has been provided. You also write the statements that make up the body of the loop. The source code file already contains the necessary variable declarations and output statements. Each theater patron enters a value from 0 to 4 indicating the number of stars the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie. Instructions Ensure the file named MovieGuide.java is open. Write the while loop using a sentinel value to control the loop, and write the statements that make up the body of the loop to calculate the average star rating. Execute the program by clicking Run. Input the following: 0, 3, 4, 4, 1, 1, 2, -1 Check that the average…Lab Assignment For this week's lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod (int size, char inputBin[size]); int dtob (int input Dec); The algorithm for the main () function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use scanf () to get that value 4. If getting it as a string, use strlen() to find the length of the string 5. Call btod () function sending to it the size and the value that was entered by the user and save the return value so the result can be printed out 2 6. Prompt user to enter a decimal number 7. Use scanf () to get that value 8. Call dtob () function saving the return value in a variable so the result can be printed out
- In C++ Declare a constant “ SIZE = 5 ” Declare an array of ints , of size SIZE . Initialize that array to have the values 10, 12, 15, 19, 6 . – Write a loop that calculates and prints out the minimum value of the array. – Write a loop that calculates and prints out the maximum value of the array. – Write a loop that calculates and prints out the average value of the array.Using C++ Write the section of code which takes an array of characters and copies it to another array of characters. At this point two arrays of characters should hold the same name. You will need to use one of the loop instructions to do this. You can't use any built in functions. Write a second section of code which concatenates two arrays of characters into a third array of characters. The first array (which holds the first name) will be copied into the third array and the second array (which holds the last name) will be concatenated onto the third array. Once you are done filling in the arrays you should output the two sentences below. You are given the example input and output below.Example Input: Input first name -> FredInput last name -> SmithExample output: Your first name is Fred and the copy of your first name is Fred. Your first name is Fred and your last name is Smith and the concatenation is FredSmith.(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.