| Lysanity (12) | |
|
Write an algorithm that determines the highest and lowest among 3 numbers. Assume that the 3 numbers are unique. Can anyone help me with codes for this problem? thank you | |
|
|
|
| Darkmaster (341) | |||
but i dont think that was your task here. you probably need to find the min/max on your own. edit: forgot & | |||
|
Last edited on
|
|||
| Lysanity (12) | |
| The highest number and the lowest number should be printed. | |
|
|
|
| Lysanity (12) | |
|
I'm going to input for 3 times for each variable. we are tasked to print the highest and the lowest number among the 3. | |
|
|
|
| Darkmaster (341) | |||
| |||
|
|
|||
| chipp (506) | |
| we don't do your homework here... please try to write your own code at first place... | |
|
|
|
| mathlo (3) | |
|
Hi, i am a begginer too... So i know my code is not perfect (at all) and very long, but it actually works... Just improve it, it might help you : #include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; int main() { int number[] = {0,0,0}; bool equal = true; int switcher = 0; srand(time(0)); for (int i=0; i < 3; i++){ number[i] = rand() % 100; for(int a = 0; a < 3; a++){ if (a!= i && number[a] == number[i] ){ number[i] = rand() % 100; } } } cout << "numbers : "; for (int i=0; i < 3; i++){ cout << number[i] << " "; } cout << endl << endl; for (int i=0; i < 3; i++){ for (int x=0; x < 3; x++){ if (number[i] > number[x]){ switcher = number[i]; number[i] = number[x]; number[x] = switcher; } } } cout << "In order : "; for (int i=0; i < 3; i++){ cout << number[i] << " "; } return 0; } | |
|
|
|
| Darkmaster (341) | |||
@mathalo: maybe you want to try this:
| |||
|
|
|||