#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 :)))

Recommended Answers

All 12 Replies

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.

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

that wouldnt work b/c its comparing each digit separately

I think I understand, take a look at the getch() function, http://en.wikipedia.org/wiki/Conio.h

If you dont want to do that you will have to use ints and use the modulo (%) operator to get each digit.

What would it look like for the MOD operator

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.

all we have learned is #include <iostream>

while( /*condtion of getch() is a ASCII enter */ )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.