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 5668
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |