Question

C++ Weight Statistics Write a program that monitors monthly weight loss each of 12 months into...

C++

Weight Statistics

Write a program that monitors monthly weight loss each of 12 months into an array of doubles.

The program should calculate and display the total weight loss for the year, the average monthly

weight loss, and the months with the highest and lowest amounts.

Input Validation:

Do not accept negative numbers for monthly weight loss.

Write your code here:

Use the Snipping Tool to show output

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

Thanks for the question.


Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.


Thank You!


===========================================================================

#include<iostream>
#include<string>
using namespace std;


int main(){
  
   double weight_loss[12];
   string months[] ={"January","February","March","April","May","June","July",
                       "August","September","October","November","December"};
   for(int month=1; month<=12; month++){
      
       do{
           cout<<"Enter weight loss for month "<<months[month-1]<<": ";
           cin>>weight_loss[month-1];
           if(weight_loss[month-1]<0) cout<<"\nSorry! weight loss cannot be negative.\n\n";
      
       }while(weight_loss[month-1]<0);
      
   }
  
   double total_loss=0.0;
   int lowest_index=0;
   int highest_index=0;
  
   for(int i=0; i<12; i++){
       total_loss+=weight_loss[i];
       if(weight_loss[i]>weight_loss[highest_index]) highest_index=i;
       if(weight_loss[i]<weight_loss[lowest_index]) lowest_index=i;
   }
  
   cout<<"\n\nTotal weight loss: "<<total_loss<<" lbs\n";
   cout<<"Average weight loss per month: "<<total_loss/12<<" lbs\n";
   cout<<"Highest weight loss was in month "<<months[highest_index]<<" and it was "<<weight_loss[highest_index]<<" lbs\n";
   cout<<"Lowest weight loss was in month "<<months[lowest_index]<<" and it was "<<weight_loss[lowest_index]<<" lbs\n";
  
  
  
}

====================================================================

============================================================================

let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer.

Thanks!

Add a comment
Know the answer?
Add Answer to:
C++ Weight Statistics Write a program that monitors monthly weight loss each of 12 months into...
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
  • Write a program in C++ that lets the user enter the total rainfall for each of...

    Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.

  • Rainfall Statistics Write a program that lets the user enter the total rainfall for each of...

    Rainfall Statistics Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November, December....

  • Write a program that lets the user enter the total amount of money spent on a...

    Write a program that lets the user enter the total amount of money spent on a credit card for each of 12 months into an array of doubles. The program should calculate and display the total amount of money spent for the year, the average monthly spent, and the months with the highest and lowest amounts. Input Validation: Do not accept negative numbers for monthly credit card charges. If the credit card charge for the month is negative, assume the...

  • Design a program that lets the user enter the total rainfall for each of 12 months...

    Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amount. PLEASE MODULARIZED THE CODE   PLEASE USE C PROGRAMMING AND ADD PSEUDOCODE

  • read it carefully C++ Question: Write a program that dynamically allocates an array large enough to...

    read it carefully C++ Question: Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not...

  • Write a program that scores the total rainfall for each of 12 months into an array...

    Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...

  • Write a program that stores the total amount of rain for each month in an array....

    Write a program that stores the total amount of rain for each month in an array. Prompt the user for the values for each month to load the array. Display this information back to them in a nice format with the name of the month and the rainfall for that month. Display back the total rainfall for the year, the average monthly rainfall, the month with the most rain, the month with the least rain, the months with rainfall above...

  • Write a C++ console application that allows your user to capture rainfall statistics. Your program should...

    Write a C++ console application that allows your user to capture rainfall statistics. Your program should contain an array of 12 doubles for the rainfall values as well as a parallel array containing the names of the months. Using each of the month names, prompt your user for the total rainfall for that month. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should...

  • Problem: You will write a program a C++ to compute some statistics based on monthly average...

    Problem: You will write a program a C++ to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

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