I"m practicing writing code and learning how to use array. I'm able to input the data..but the data that gets spit from the array is wrong once I put in the number 100, or the total of all the values input = 100 or more..
example..if I put in 5, 10 15.. the output would be 5,10,15..so far so good.
but if i put in 5, 100, 10 15.. the output would be 5, and then garbage..
or if i input 85,15..the output would be 85..and then garbage..cause the total is over 100...I don't get why it cares about the total of the input..when its just storeing the values in a space.. it shouldnt be totaling the values..
ok when I tried to use the sentinal to control the loop, for some reason it would not apply the value ton myint.. unless i assigned the value to myint after it is input ino the array..
if I left out myint = view[myint]; I can't use the -1 to get out of loop
Ok so like i said this is practice code. I use portion of that code in another program that worked out fine..but the key thing Im trying to figure out is why I wont print out the correct data after 100 as I said above.. the code in betwween 22-32 was part of an if statement to make sure the person only input grade value between 0 and 100 anything outside of that would get rejected..
Ok I think I get get what you mean but lets try doing it a different way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int a = 0;
int temp;
while (a < 1000) {
cout << "Please insert grade between 0 and 100: " << endl;
cin >> temp;
if (temp == -1) {
break;
}
elseif (temp < 0 || temp > 100) {
cout << "Please insert a number between 0 and 100: " << endl;
}
else {
view [a] = temp;
a++; // a will double over as size in all truth.
}
}
This is what I believe you want or at least something similar to this. This is a possible replacement for lines 22-32 some of your other code will have change slightly.
Ok that seems to work, however it seems I cant use float or double in the array. when i change temp to a float and the array to a float..I get an error, same when I change them both to double... any idea why?
Please insert grade between 0 and 100:
7.89
Please insert grade between 0 and 100:
92
Please insert grade between 0 and 100:
101
Please insert a number between 0 and 100:
Please insert grade between 0 and 100:
-2
Please insert a number between 0 and 100:
Please insert grade between 0 and 100:
56
Please insert grade between 0 and 100:
76.7
Please insert grade between 0 and 100:
-1
grade0 is 7.89 numbers.
grade1 is 92 numbers.
grade2 is 56 numbers.
grade3 is 76.7 numbers.
Press any key to continue . . .
However, keep in mind I altered your code just a bit to reflect how I would write and got rid of some unnecessary variables and comments. I'll post below: