![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Illinois--> My room
Posts: 117
Rep Power: 0
![]() |
One more question infinite!
Accept 10 numbers, and find the largest and second largest numbers. You MUST use a while loop
Here's my code thus far: #include "stdafx.h" #include <iostream> using namespace std; int main() { int number = 0, MAX = 0, MAX1 = 0 count = 1; while (count <= 10) { cout << "Enter 10 numbers to find the maximum: "; cin >> number; if (number > MAX) { MAX = number; } if (number > MAX1) { MAX1 = number; } count++; } cout << MAX << " is the maximum" << " and " << MAX1 << " is the second maximum!" << endl; return 0; } and I have no idea where to go from there, There's nothing wrong with th at code, except it prints the max for both MAX and MAX1. I don't know how to get the second largest number...
__________________
Support Our Troops |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Illinois--> My room
Posts: 117
Rep Power: 0
![]() |
// Exercise 4.19 Two Largest Numbers.cpp : Defines the entry point for the console application.
// #include "stdafx.h" #include <iostream> using namespace std; int main() { int number = 0, MAX = 0, MAX1 = 0, count = 1; while (count <= 10) { cout << "Enter 10 numbers to find the maximum: "; cin >> number; if (number > MAX) { MAX = number; } else if (number > MAX && number > MAX1) { MAX1 = MAX; MAX = number; } count++; } cout << MAX << " is the maximum" << " and " << MAX1 << " is the second maximum!" << endl; return 0; } NEvermind, I figured it out... guess I'm just tired... too bad it took me so long, so thanks anyways ![]()
__________________
Support Our Troops |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Illinois--> My room
Posts: 117
Rep Power: 0
![]() |
damn, nevermind, it's not working now, i keep geting 0 for the second maximum
god dang, stuff like this is hard, but directx buffering and blitting is easy... what a world
__________________
Support Our Troops |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Illinois--> My room
Posts: 117
Rep Power: 0
![]() |
dang, it still gives me 0 for the second value:
#include "stdafx.h" #include <iostream> using namespace std; int main() { int number = 0, MAX = 0, MAX1 = 0, count = 1; while (count <= 10) { cout << "Enter 10 numbers to find the maximum: "; cin >> number; if (number > MAX) { MAX = number; } if (number > MAX1 && number < MAX) { MAX1 = number; } count++; } cout << MAX << " is the maximum" << " and " << MAX1 << " is the second maximum!" << endl; return 0; }
__________________
Support Our Troops |
|
|
|
|
|
#6 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Illinois--> My room
Posts: 117
Rep Power: 0
![]() |
oh duh, ok I see it now.
Thanks MJordan2nd
__________________
Support Our Troops |
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
beat me to it....
gw
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#9 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
![]() No problem!
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|