look, there are certain issues in your program:
1. None of your variables are initialized. C++ being a native language, doesn't automatically initializes anything. Now when you declare a variable, it simply allocates some storage space for it. That storage space will contain some value and not zero ( as u may be expecting ).
2. userNumOne == maxNum;
This statement doesn't makes any sense, were u trying to use '=' instead. '==' is a relation operator it does not assigns anything.
3. you are using string object called as "again", now writing like again['y'] is not at all similar to what your intention may be. it calls the overloaded operator[] of string class, which is a random access operator. You are asking the string object to return you a char value located at a index of 97 (the ascii value of 'y'), your string doesn't have that many characters, that's what the error is which u r getting.
If you are new to c++, then read about overloading operator[] and string class of stl. what you could have simply done is
1 2 3 4 5 6 7 8 9 10
|
char again; //instead string.
.....
.....
cin >> again;
.....
.....
while ( again == 'Y' || again == 'y')
.....
.....
|
lastly your program has a logical error.
a proper logic would be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
maxNum = userNumOne
if (userNumOne < userNumTwo)
{ maxNum = userNumTwo;
}
if ( maxNum < userNumThree)
{ maxNum = userNumThree ;
}
minNum = userNumOne;
if ( userNumOne > userNumTwo)
{ minNum = userNumTwo ;
}
if ( minNum > userNumThree)
{ minNum = userNumThree ;
}
|
hope you can compile and run !!