I dont know where I am going wrong so I dont know which part to post, this is what I have, can anyone help me figure out where I am going wrong? THanks for any and all help. -
// into to c++
-
// This program should use a loop that lets the user enter a series of integers.
-
// The user should enter -99 to signal the end of the series.
-
// After all the numbers have been entered,
-
// the program should display the largest and smallest numbers entered.
-
-
#include <iostream?
-
using namespace std;
-
-
int main()
-
-
{
-
//enter up to 5 integers
-
int least, int greatest; //determine least and greatest
-
-
-
double num1 = 0;
-
double num2 = 0;
-
double num3 = 0;
-
double num4 = 0;
-
double num5 = 0;
-
-
-
cout << " Please enter up to 5 integers:\n ";
-
cin >> num1, num2, num3, num4, num5;
-
-
cout << " The integer with the least value is: \n";
-
cin >> least;
-
-
cout << " Of the integers you choose the one with the greatest value is: \n"
-
cin >> greatest;
-
-
if ( num1 < num2 )
-
least = num1;
-
-
else if ( num2 < num3)
-
least = num2;
-
-
else if ( num3 < num4)
-
least = num3;
-
-
else if ( num4 < num5)
-
least = num3;
-
-
else if ( num 5 < num1 )
-
least = num5
-
-
if ( num1 > num2 )
-
greatest = num1;
-
-
else if ( num2 > num3)
-
greatest = num2;
-
-
else if ( num3 > num4)
-
greatest = num3;
-
-
else if ( num4 > num5)
-
greatest = num3;
-
-
else if ( num 5 > num1 )
-
greatest = num5
-
-
-
if( user input == -99 ) break;
-
-
return 0;
-
-
}
-
3 5645
Check out if elseif
suppose you have 10, 12, 1, 2, 3 as your numbers input
cause 10<12, so that num1<num2 is satisfied, and then num1(10) is your least
so that you won't go any further of the ifelse condition. but this is not right.
You might want to do than pairwise, like say
num1 compare with num2 , you get a min and max
num3 compare with num4 , you get a min and max
and then you compare the two mins together with num5 to determin the min
compare the two max together with num5 to determin the max as well,
Remember if from math perpective, in order to compare 5 numbers , you need at least 10 comparisions, apparently you don't, that is why your code doesn't work.
Hope it helps!!!
JJ
Sounds like our OP needs to open up his C++ book and do some reading.
Delete your entire program. Now start from scratch. Do just step one. That is, write a loop that allows the user to enter a series of integers. A loop.
If you don't know how to write a loop or an array, that's a sign you don't know the material at all. And we can't help if your issue is not knowing the material.
Also, you cannot use operators line <, >, ==, !=, etc with floating point.
The rounding of floating point causes these operators to report something is true when the numbers may not be in that exact relation but only close in value.
Try a Google on Floating Point Arithmetic and you will see what I mean.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Johnny Knoxville |
last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works
fine if you add the site to favourites the normal way, but I have some
JavaScript code on a couple of pages with a link,...
|
by: brian.digipimp |
last post by:
Write a program that prompts the user to input a positive integer. It
should then output a message indicating whether the number is a prime
number. (Note: An even number is prime if it is 2. An odd...
|
by: ash |
last post by:
Hey I am new, but I don't have time to intruduce myself yet.
I am intro to C++
and this is a programme I have to write.
all the direction are here, It will be very nice of someone to figure
this...
|
by: Amadej |
last post by:
Hello everyone,
I need some advice on which class to use when working with an XML file
in a specific way. Basically I am writing a program, that needs to
save it's state into a file, so it can...
|
by: Mike Nolan |
last post by:
As far as I can tell, Postgres has no equivalent to greatest and least
functions in Oracle. Yes, you can do the same thing with a case statement,
but at the expense of writing MUCH longer SQL...
|
by: rami |
last post by:
please everybody ,can anyone tell me how to do an infinite loop in C
|
by: daveyand |
last post by:
Hey Guys,
I've stumped.
I created a function that does various things to select boxes.
Namely
Get All selected indexes,
populate array with these values
|
by: preethamkumark |
last post by:
- The program first creates a shared memory buffer containing an array
of 20 integers.
- Each slot of the buffer can have either 0 or 1, where 0 represents an
empty slot, and 1
represents an...
|
by: mturner64 |
last post by:
Good day. I am working on a program that will allow a user to enter an undefined series of numbers and enter -99 when finished. The program should output the Greatest and Least of the series...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |