Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Calculating sum of series is an important concept. We like to write a program to solve the following sum. S = - (k +

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1. Calculating sum of series is an important concept. We like to write a program to solve the following sum. S = - (k + 1)/k k=1 Don't let the math scare you! This is just a loop that starts from 1 and goes up to n. We simply add the terms (k+1)/k. Written in the long form; it looks like: s= 2/1 + 3/2 + 4/3 + ... (n+1) as an example, when n = 5, we get s = 2/1 + 3/2 + 4/3 + 5/4 + 6/5 = 7.2833 a) Ask the user for a value for n b) Validate the value of n to make sure it's 1 or more. Give the user 3 tries to get it right. If the number is invalid after 3 tries, set s =-1 c) Display each of the values of k and k+1 as shown in the sample run. d) Display the value of s with 4 digits after the decimal point 2. We like to process items that a user wishes to purchase. a) We like to be able to have the user enter prices for as many items that she wants to purchase. Allow for a sentinel value to end the input loop. You may pick a negative number as the sentinel value. b) Do not allow the user to enter an invalid price (a price greater than $200). Issue an error message and allow the user to enter a valid price. c) Calculate and display the total amount of all purchases and the number of items purchased. d) Calculate and display the average price of all purchases. e) Calculate and display the lowest price of all purchases. (see NOTE, after the sample interactions for pseudocode and explanation for finding the lowest value) f) Calculate and display the highest price of all purchases. g) If the user enters the sentinel value at the beginning of the processing, the code should display a message such as There is nothing to process! Here is a sample run: Your code must run with any sets of input Sample interaction 1: Enter a value for the final value of the series: -900 Invalid input: Enter a value for the final value of the series: 0 Invalid input: Enter a value for the final value of the series: 5 Enter a value for the final value of the series: 5 2/1 +372 +4/3 + 5/4 + 6/5 = 7.2833 Welcome to Bargain Basement Where bargains are our business! Please enter the item price. Type -1 when finished: -1 Thanks for using my program - there was no data to process

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

=+What forms of industrial action are common?

Answered: 1 week ago