#include <iostream>

using namespace std;

    int main()
       char a, b, c, d, e, f, max;

       cout << "enter a b c: ";
       cin >> a >> b >> c >> d >> e >> f;

       max = a;
        max = b;
        if (c>max)
        max = c;
        if (d>max)
        max = d;
        if (e>max)
        max = e;
        if (f>max)
        max = f;
        cout << "max is " << max << "\n";
        return 0;


Ok I need to add a break somewhere so if input is 123 or 1245..it doesnt just work for input of 5 CHAR

* Im thinking of a for while loop but not too sure
* Or a variable to keep the actual "current maximum" and, every time the user inputs a new number, have it compare the "current maximum" with the new number: if the current maximum is greater it would simply discard the new input, if it's less, instead, the new input becomes the new maximum.
* Or move a cin inside the loop for a check

thanks all :)))

If what you want to do is use a loop to test the chars rather than a bunch of if statements then you will have to use an array.

I dont mind using the if statements..all I really want to do is add some type of break so that if its 2 3 4 5 then it works

I dont fully understand, is the issue that not all of the letters are being entered? or that the order is so close?

Ok with the code I have u under 123456..and it prints 6...but if input 12 123 1234 12345 it doesnt work..it has to have six char input..I want to make it so 12 123 1234 12345 also works..please helpsyy :))) tyy <3

oh that is easy, change the chars into ints, they have a larger range.

that wouldnt work b/c its comparing each digit separately

What would it look like for the MOD operator

Edited 5 Years Ago by meli123: wrong post

If you don't have to use a loop, here is an awesome way of doing this:

#include <vector>
#include otherstuffyouneed

using namespace std ; 

int main() { 

vector<char> cvec ; 
vector<char>::iterator cit ; 
 cout << " Enter yo stuff " << endl; 
cin >> a >> b >> c >> d >> e >>f  ; 
cvec.push_back(a) ; 
cvec.push_back(b ) ; 
cvec.push_back( c) ; 
cvec.push_back( d) ;
cvec.push_back(e ) ; 

sort(cvec.begin() , cvec.end() ) ; 

/* And voila , your biggest element is at the end */ 

cout << cvec[cvec.size() -1 ] ; 

return 0 ;

btw, I think it's #include <algorithm> that you need for that.

you don't need the vector<char>::iterator part, meant to take that out.

cvec.push_back(whatever) adds an element to the end of the array

And when we are printing always remember to print size -1 or you will prob get a seg fault.

This article has been dead for over six months. Start a new discussion instead.