C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5.5, Problem 2E
(cin within a loop) Write and run a C++
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q) Write a program in C++ that takes a number n from User.This program computes the sum of reciprocals of numbers up to n using a loop.
S = 1 + 1/2 + 1/3 + 1/3 + ... + 1/n
and shows the value of S on screenNote: to Calculate S you can use while loop, do...while loop or for loop.
-Program C
3. Negative Allergy
by CodeChum Admin
Whole numbers are great, but I think we should also pay attention to decimal numbers, too.
So, how about we make a program that involves a lot of decimals?
Instructions:
Continuously ask for floating point values (decimal numbers) using the do…while() loop, sum them all up, and store the total into one variable.
The loop shall only terminate for the following reasons:
A negative decimal number is inputted (but still included in the total sum)
The total sum reaches 100.0 or more
Input
1. A series of float numbers
Output
The first multiple lines containing message prompts for float numbers. The last line contains the sum with 2 decimal places.
Enter·a·number:·1.1
Enter·a·number:·1.2
Enter·a·number:·1.3
Enter·a·number:·1.4
Enter·a·number:·-1.0
Sum·=·4.00
(python)
Study the following code, specifically the loop.
_sum = 10
for k in range (2, 20, 3):
_sum = _sum + (2*k)
if _sum > 100:
print("exceeded 100")
Now, rewrite the for loop (for k in range(2, 20, 3):)to be a while loop that accomplishes the same objective. You don't need to show/use the other lines.
Chapter 5 Solutions
C++ for Engineers and Scientists
Ch. 5.1 - (For review) List the three repetition statements...Ch. 5.1 - Prob. 2ECh. 5.1 - (For review) a. What’s the difference between a...Ch. 5.2 - (Practice) Rewrite Program 5.1 to print the...Ch. 5.2 - (Practice) Rewrite Program 5.4 to produce a table...Ch. 5.2 - (Conversion) Write a C++ program that converts...Ch. 5.2 - (Practice) An automobile travels at an average...Ch. 5.2 - (Numerical analysis) a. The following is an...Ch. 5.2 - Prob. 9ECh. 5.3 - Prob. 1E
Ch. 5.3 - (Conversion) a. Write a C++ program to convert...Ch. 5.3 - (Misc. application) a. The data in the following...Ch. 5.4 - (Practice) Write a for statement for each of the...Ch. 5.4 - (Desk check) Determine the value in total after...Ch. 5.4 - Prob. 5ECh. 5.4 - (Conversion) Write a C++ program to convert...Ch. 5.5 - (cin within a loop) Write and run a C++ program...Ch. 5.5 - Prob. 4ECh. 5.5 - Prob. 5ECh. 5.5 - Prob. 7ECh. 5.5 - (Program) Write a program that tests the...Ch. 5.5 - Prob. 14ECh. 5.5 - (Program) Write a program to simulate the rolling...Ch. 5.6 - (Misc. application) Four experiments are...Ch. 5.6 - (Electrical eng.) a. An electrical manufacturer...Ch. 5.6 - (Mathematical functions) Write a program that...Ch. 5.6 - Prob. 6ECh. 5.7 - (Practice) a. Using a do statement, write a...Ch. 5.7 - (Misc. application) a. Write a program that...Ch. 5.7 - (Misc. application) a. Write a program to reverse...Ch. 5.7 - Numerical analysis) Given a number, n, and an...Ch. 5.7 - (Numerical analysis) Here’s a challenging problem...Ch. 5 - (Probability) The probability that a phone call...Ch. 5 - (Mechanics) The deflection at any point along the...Ch. 5 - (Physics) A golf ball is dropped from an airplane....
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- C++ Write a program that will output the square root of any number entered through the keyboard, until the inputted number, is zero. (Hint: using loop)arrow_forwarddo not submit this one) Write a C++ program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches in a foot. (do not submit this one) Write a C++ program like that of the previous exercise that converts from meters and centimeters into feet and inches. Use functions for the subtasks. (submit this one) Write a C++ program that combines the functions in the previous two Practice Programs. The program asks the user if he or she wants to convert from feet and inches to meters and centimeters or from meters and centimeters to feet and inches. The program then inputs the values and performs the desired conversion. Have the user respond by…arrow_forwardPART 2 (Lab) a. Write a C+ program that asks the user to enter N, the program should then output the Fibonacci series. Use do-while loop to ask user to re-enter N if the user entered a number below 2. Hint: The first two numbers in the Fibonacci series are 0 and 1. F, = 0 F, = 1 Any Fibonacci number is equal to the summation of the two previous numbers Fn = Fn-1+ Fn-2 Therefore, F, + F, = 1+ 0 = 1 F, + F, = 1+1= 2 F4 = F3 + F2 = 2 +1 = 3 F2 .... FN = FN-1 + FN-2 Enter N: 20 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 b. Write a program that use loops to print the following patterns separately, one below the other. In your code use for, while and do-while loops to generate the patterns, use one loop for each question. * ********* ** ******* *** ***** **** *** ***** *arrow_forward
- (In python please) Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs Yes if every character is a digit 0-9 or No otherwise. Ex: If the input is: 1995 the output is: Yes Ex: If the input is: 42,000 or any string with a non-integer character, the output is: Noarrow_forwardObjective: Implement programs involving the use of while, do..while and for loop statement. Problem: Write a program to display the output below:arrow_forwardPlease use C++ code and only use the libraries <iostream> and <cmath>. Hints given: 1) Read first term and common ratio 2) Make sure common ratio is valid 3) Compute the sum of the series using the formula 4) Write a while loop to compute the sum by adding terms to the series until it agrees with the formula sum to 7-digits 5) Print formula answer, the answer by adding terms, and the number of terms added. Use cout.precision(10) and don't set fixed or scientific notationarrow_forward
- Need help with this while loop question: (Please do this in Python programming) Using while True loop that: Prompts the user to enter a word; may use one input statement in function Calculates the number of words entered with an upper case first letter Presses (hits) the Enter/Returns key on the keyboard, without typing anything to signal the end of the loop Once the loops end, the function should return (not print) one of the following messages: "0 words were entered" "Words with upper case first letter = x', where x is the number of words maybe 0 if no words entered had an upper case first letter The output needs to look like this: (see image attached)arrow_forward(Comparing Integers) Write a program that prompts the user to enter the edges of a triangle and compares them. If all edges are equal, display Equilateral Triangle; if only two edges are equal, display Isosceles Triangle and if none of the edges are equal, display Scalene Triangle. Use c++ program.arrow_forward- Assignment # 1 Q1) Write a C++ program that reads a five-digit integer value representing MINUTES. The program should then find how many weeks, days, hours, and minutes that number represents. Example: Enter number of minutes: 13216 13216 minutes equals 1 week, 2 days, 4 hours, 16 minutes. Q2) Write a C++ program that takes 3 real numbers from the user and prints their minimum, maximum and average. Show two decimal positions in the output. Example: Enter three real numbers> 5.2 6.7 4.0 Minimum is 4.00 Махітит is 6. 70 Average is 5.30 Q3) Write a C++ program that reads three marks out of 100, computes their average M, then prints the grade (as shown in the example) according to the following scale: M>= 90 : A (Excellent), 90 > M>= 80 : B (Very Good) , 80> M>= 70 : C (Good), 70> M>= 60 : D (Pass), M< 60 : F (Fail). Example: Enter three marks: 70 80.5 62.5 Your Grade is C GOODarrow_forward
- (IN C LANGUAGE) Binary-Decimal / Decimal Binary . Between 0 and 255 a number will be decided randomly by computer. Then asks to user 3 times a random digit of binary value of the that number. If user enters wrong number for a digit program will select another random number and ask random times random digit. For example: Computer selected number as 163 ( Which is 10100011) What is the digit 2 (question 1/3) :User enter 1 CorrectWhat is the digit 4 (question 2/3) : User enter 0 CorrectWhat is the digit 7 (question 3/3) : User enter 0 CorrectUser finished the quest with 3 input .arrow_forwardC++ pls (use only while-loop. using for-loop will not get any credit.) Ask user how many grades you have. then ask them to enter those grades (this is a outer while-loop), then each time validate a grade(this is inner while-loop), then when you got all valid grades, find the average.arrow_forward(Bar-Chart Printing Program) One interesting application of computers is drawing graphsand bar charts. Write a program that reads five numbers (each between 1 and 30). For each numberread, your program should print a line containing that number of adjacent asterisks. For example,if your program reads the number seven, it should print *******.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License