Hello,
i have 2 input-types int. They have to be bigger than the ones before. Start values is 0 and -1;
Allowed Values:
{ 31,32,41,42,43,51,52,53,54,61,62,63,64,65,11,22,33,44,55,66,21 }
So after 32, valid values are: 41,42,43...
31 and 32 are not allowed.
But with the code i get this to only work one time, then i can type in a bigger number and the output says its a smaller one.
heres the code which works one time::
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <string>
using namespace std;
bool compare(int max, int min, int input1, int input2) //true = input bigger then value before
{
if ((input1 == 2) && (input2 == 1))
{
return true;
}
else if ((max == 2) && (min == 1))
{
return false;
}
else if ((max == min) && (input1 == input2)) // both doubles
{
if (max > input1)// input is lower
{
return false;
}
else //input is higher
{
return true;
}
}
else if (max == min) //old input is a double
{
return false;
}
else if (input1 == input2) //new input is a double
{
return true;
}
//no double
else if (max > input1) //Input is lower than old value
{
return false;
}
else if (max < input1) //Input is higher than old value
{
return true;
}
else // old value1 = new value1 -> compare value2
{
if (input2 > min) //new input is bigger
{
return true;
}
else if (input2 == min) // both are equal
{
return false;
}
else //Input is lower
{
return false;
}
}
}
int a = 0;
int b = -1;
int tempa;
int tempb ;
int main()
{
int tempValue1, tempValue2, Value1, Value2;
tempValue1 = 0;
tempValue2 = -1;
do {
cin >> Value1;
cin >> Value2;
if (compare(tempValue1, tempValue2, Value1, Value2))
{
cout << "Input is bigger!" << endl;
tempValue1 = Value1;
tempValue2 = Value2;
}
else
{
cout << "Input is smaller!" << endl;
}
} while ((tempValue2 > tempValue1) && (compare(tempValue1, tempValue2, Value1, Value2) == false));
system("pause");
return 0;
}
| |
now the code with the error, cause i goes up(do-while breaks)even though i dont want it to do so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <string>
using namespace std;
bool compare(int max, int min, int input1, int input2) //true = input bigger then value before
{
if ((input1 == 2) && (input2 == 1))
{
return true;
}
else if ((max == 2) && (min == 1))
{
return false;
}
else if ((max == min) && (input1 == input2)) // both doubles
{
if (max > input1)// input is lower
{
return false;
}
else //input is higher
{
return true;
}
}
else if (max == min) //old input is a double
{
return false;
}
else if (input1 == input2) //new input is a double
{
return true;
}
//kein Pasch
else if (max > input1) //Input is lower than old value
{
return false;
}
else if (max < input1) //Input is higher than old value
{
return true;
}
else // old value1 = new value1 -> compare value2
{
if (input2 > min) //new input is bigger
{
return true;
}
else if (input2 == min) // both are equal
{
return false;
}
else //Input is lower
{
return false;
}
}
}
int a = 0;
int b = -1;
int tempa;
int tempb ;
int main()
{
int tempValue1, tempValue2, Value1, Value2;
tempValue1 = 0;
tempValue2 = -1;
for (int i = 0; i < 10; i++)
{
do {
cout << "Player " << i + 1 << ", pls enter your values here: " << endl;
cin >> Value1;
cin >> Value2;
if (compare(tempValue1, tempValue2, Value1, Value2))
{
cout << "Input is bigger!" << endl;
tempValue1 = Value1;
tempValue2 = Value2;
}
else
{
cout << "Input is smaller!" << endl;
}
} while ((tempValue2 > tempValue1) && (compare(tempValue1, tempValue2, Value1, Value2) == false));
}
system("pause");
return 0;
}
| |