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

  • Home
  • SEARCH
  • 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 8616385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:36:25+00:00 2026-06-12T05:36:25+00:00

I was attempting to write a program for exercise 2.19 in How to Program,

  • 0

I was attempting to write a program for exercise 2.19 in How to Program, but I ran into some difficulties.

The program is supposed to have the user enter three integers and then display the sum, average, and product of those integers.

The only problem I am having is with displaying the largest and smallest. When I ran the program and entered three integers (8, 9, and 10), the output read Smallest is 8 AND Smallest is 9.

I was hoping you could tell me why.

#include <iostream>
using namespace std;

int main ()
{   int x, y, z, sum, ave, prod;

    cout << "Input three different integers ";
    cin >> x >> y >> z;

    sum = x + y + z;
    cout << "\nThe sum is " << sum;

    ave = (x + y + z) / 3;
    cout << "\nThe average is " << ave;

    prod = x * y * z;
    cout << "\nThe product is " << prod;

    if (x < y, x < z)
      {cout << "\nSmallest is " << x;}

    if (y < x, y < z)
      {cout << "\nSmallest is " << y;}

    if (z < x, z < y)
      {cout << "\nSmallest is " << z;}

    if (x > y, x > z)
      {cout << "\nLargest is " << x << endl;}

    if (y > x, y > z)
      {cout << "\nLargest is " << y << endl;}

    if (z > x, z > y)
      {cout << "\nLargest is " << z << endl;}

    return 0;
}

P.S. I am doing this to study, this is not homework.

  • 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-12T05:36:26+00:00Added an answer on June 12, 2026 at 5:36 am

    You need to rewrite this if condition

    if (x < y, x < z)
    

    to be

    if (x < y && x < z)
    

    and do the same for all of the remaining if conditions you have.

    Edit:
    All experssions seperated by comma will be evaluated so if you have something like that
    x = 5, y = 6; it will evaluate both of them and set x to 5 and y to 6
    but
    z = (x=5, y=6); this will cause z to be set to 6 just like y as y=6 was the last term in the list of comma separated terms.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write a program that waits for readline input, but only for
I have been attempting to write a program that will determine if a number
Ok, I need some help here. I'm attempting to write a program that rolls
I have been attempting to write a VBA Script that can parse out other
I am attempting to write my first Dynamics Crm 2011 plugin. I have therefore
i'm attempting to write the result of the $x = [System.Net.Dns]::GetHostAddresses($name) statement into my
I'm attempting to write a program in which children processes communicate with each other
I'm currently attempting to write my own program that mirrors the pmap command, specifically
http://pastebin.com/uws2Ts96 - my program so far I'm attempting to write a C program for
I'm attempting to write a short mini-program in Python that plays around with force-based

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.