Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:42:53+00:00 2026-06-13T23:42:53+00:00

Hi I’m needing some help. I’m in a intro to programming class and we

  • 0

Hi I’m needing some help. I’m in a intro to programming class and we are using c++. I am hoping someone can help me with an assignment that was due yesterday (I understand not to expect miracle responses but a girl can always try).

I’m having two problems that I know of. The first is regarding the smallest value.
The big one is in trying to make it loop for requirements of three times but not lose out on my total count. I cannot use arrays or anything I haven’t learned yet which is why I’ve posted this. I’ve seen similar problems and questions but they have ended up with answers too complex for current progress in class. So here is the problems instructions:

Instructions
1) Write a program to find the average value, the largest value, and the smallest value of a set of numbers supplied as input from the keyboard. The number of values in the data set must be in the range 0 to 20, inclusive. The user will first enter the number of values in the data set(use variable int Number). Give the user 3 attempts at entering Number in the range given. If the value for Number entered is out of this range, write an error message but continue. If the user does not enter a valid value for Number within the 3 attempts print an error message and terminate the program.

2) Format only the output for the Average value to 3 decimal places when printed.

3) The values in the data set entered as input can be any value positive, negative, or zero.

4) Make the program output readable(see the example below). (Note: that you will notprint out the input values that were entered in this program like you normally are required to do. This is because we have not covered the “tool” needed to do so yet in our studies).

Below will be the output from the execution of your program:
(using these values in order for the data set –> 19.0 53.4 704.0 -15.2 0 100.0)

The largest number:  704
The smallest number:  -15.2
The average of the 6 numbers entered: 143.533
yourName L4p2XX.cpp
Lab#4 prob 2 XX-XX-12

Here is my poor excuse at the solution:

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

int main()
{
    double Number = 0, minValue, maxValue, average, total = 0;
    int ct = 0, numCount;
    cout << "How many numbers would you like to enter? ";
    cin >> numCount;

    for(ct = 1; ct <= numCount; ct += 1)
    {    
        cout << "Enter Value from 0 to 20, inclusive: ";
        cin >> Number;

        if(Number > 20|| Number < 0)
            for(int errorCt = 1; errorCt <= 4; errorCt += 1)
            { 
                if(errorCt == 4)
                {  
                    cout << "You have had 3 attempts to enter a valid" <<
                            "number. \nPlease try this program again when you" <<
                            "are able to follow directions.";
                    cout <<"\nLBn\n"<<"L4P2LB.cpp\n"<<"11-05-12\n";
                    return 0;
                }
                cout << Number << "is not within range.\n" << 
                        "Please enter a number from 0 to 20: ";
                cin >> Number;
            } //end for loop

        total += Number;
        if(maxValue <= Number)
            maxValue = Number;
        if(Number <= minValue)
            minValue = Number;
    } //end for loop

    cout << "The smallest number entered was " << minValue << endl;
    cout << "The largest number you entered was " << maxValue << endl;
    average = total/numCount;
    cout << setprecision(3) << fixed << showpoint << "You entered " <<
            numCount << " numbers. The average of these is " << average;

    //Program ID
    cout <<"\n" << "L4P2LB.cpp\n" << "11-05-12\n";
    system ("pause");
    return 0;
} // End main

Thank you in advance to anyone who can steer me in the right direction. Not looking for anyone to do my work I just need help in direction if nothing else or any suggestions as to what to do. Thanks again. Lynda

Also I need somehow to pause after the third time and exit properly. If I put the second pause in it won’t work so am I missing something obvious there too!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:42:54+00:00Added an answer on June 13, 2026 at 11:42 pm

    The first problem I see is that you didn’t initialize a couple of variables.

    You should either initialize both minValue and maxValue variables with something which will overwritten in every case in the first loop (typically “positive/negative infinity”, as provided by <limits>), or just set both to Number in the first iteration, regardless of their current value. So I’d suggest to fix this by replacing

        if(maxValue <= Number)
            maxValue = Number;
        if(Number <= minValue)
            minValue = Number;
    

    with

        if(maxValue <= Number || ct == 1)
            maxValue = Number;
        if(Number <= minValue || ct == 1)
            minValue = Number;
    

    as ct == 1 will be true in the first iteration.

    That said, you check the 0..20 range condition on the wrong variable. You check it on the Number variable, but you should check the numCount variable. But you also didn’t respect the requirement that the variable to store the “number of numbers” should be Number, so you did check the correct variable, but used the wrong to read the input into. This should fix this issue (I changed the variable name in the cin >>... line + moved the check outside your main loop):

    cout << "How many numbers would you like to enter? ";
    cin >> Number;
    if(Number > 20|| Number < 0)
    {
        for(int errorCt = 1; errorCt <= 4; errorCt += 1)
        ...
            if(errorCt == 4)
            {  
                cout << "You have had 3 attempts to enter a valid" <<
                        "number. \nPlease try this program again when you" <<
                        "are able to follow directions.";
                cout <<"\nLBn\n"<<"L4P2LB.cpp\n"<<"11-05-12\n";
                return 0;
            }
            cout << Number << "is not within range.\n" << 
                    "Please enter a number from 0 to 20: ";
            cin >> Number;
        } //end for loop
    }
    
    for(ct = 1; ct <= Number; ct += 1)
    {    
        ...
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.