Alchemista more C++
alchemista like my friend is also teaching me stuff but he's also a newbie, he only took C++ for like a semester or something.. anyway is there a way for this: 1) Program asks for a number of digits 2) I enter the number say 3 3) The program asks for digit 1: I enter it and so forth until digit 3. 4) The program shows me the minimum or maximum of those digits. Is there like a command max(a,b,c) or min(a,b,c) or how do I do this?
For two digits I have: #include <math.h> #include <conio.h> #include <iostream> #include "stdafx.h" using namespace std; int main() {float First_number, Second_number, Minimum_value; cout<<"First number="; cin>>First_number; cout<<"Second number="; cin>>Second_number; if (First_number<Second_number) Minimum_value=First_number; else Minimum_value=Second_number; cout<<"Minimum value="<<Minimum_value<<"\n"; system ("pause"); return 0; }
You can use for loop for that
how?
You store the "greatest" and compare each new one against the current greatest.
Thats for max
so what would the greatest be? what if i want it to be the infinity?
For min its the other way around.
pseudo code: min = first digit loop: input = next digit if input < min: min = input break when done
you loop should go up to number of digits
float min () { int digits; float current, value; cout << "Count: " << flush; cin >> digits; cout << "Value: " << flush; cin >> current; while(--digits > 0) { cout << "Value: " << flush; cin >> value; if ( value < current ) current = value; } cout << "Min: " << current << endl; }
Join our real-time social learning platform and learn together with your friends!