Can someone help in my code I feel there is something wrong but I can't figure it out | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Can someone help in my code I feel there is something wrong but I can't figure it out

Find the second lowest integer number write a program that prompts the user to enter a set of integer numbers and finally displays the second largest integer number in the set . To exist from the program enter -1. here is sample run into a set of integer numbers: 3 5 7 9 -1 #include <iostream> using namespace std; int main() { int integer=INT_MAX; int smallest_int=INT_MAX; while (integer != -1) { if( integer < smallest_int) { smallest_int= integer; } else if (integer< smallest_int) { smallest_int = smallest_int; } cout << "Enter a set of integer numbers: "; cin >> integer; } cout << "The second lowest number is: " << smallest_int << endl; return 0; }

20th Nov 2020, 8:35 AM
Seraphina
Seraphina - avatar
4 Réponses
0
Seraphina First when you initialized integer and smalest_int you didn't give them any value because INT_MAX is not defined as well. Second your first cout and cin should be before the while loop because you are using integer in the while loop before you even call it.
20th Nov 2020, 3:01 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
+ 1
Thank you so much 👌✨
20th Nov 2020, 11:51 PM
Seraphina
Seraphina - avatar
0
Since the length of the set is unknown because it the set is done until -1 appear. You can use vector to store these numbers. And use 2 while loops to get the second smallest number. If you don't know about vector. It's a container like array but with dynamic size. The size of vector can be changed.
20th Nov 2020, 12:36 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Seraphina no problem ^^
21st Nov 2020, 12:21 AM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar