Ask your own question, for FREE!
Mathematics 21 Online
OpenStudy (bahrom7893):

Alchemista more C++

OpenStudy (bahrom7893):

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?

OpenStudy (bahrom7893):

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; }

OpenStudy (anonymous):

You can use for loop for that

OpenStudy (bahrom7893):

how?

OpenStudy (anonymous):

You store the "greatest" and compare each new one against the current greatest.

OpenStudy (anonymous):

Thats for max

OpenStudy (bahrom7893):

so what would the greatest be? what if i want it to be the infinity?

OpenStudy (anonymous):

For min its the other way around.

OpenStudy (anonymous):

pseudo code: min = first digit loop: input = next digit if input < min: min = input break when done

OpenStudy (anonymous):

you loop should go up to number of digits

OpenStudy (anonymous):

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; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!