int or double??
Why double: int linemen_weight = 0; int other_weight = 0; int total_weight = 0; ...
Instead of what I have int? (yes this is a broken code, I don't want classmates copying my code).
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
|
#include <iostream>
using namespace std;
int main() {
int k = 20;
int player_number;
int weight;
int backs = 0;
int linemen = 0;
int other = 0;
int backs_weight = 0;
int linemen_weight = 0;
int other_weight = 0;
int total_weight = 0;
while (k > 0) // Begins the loop.
{
datain >> player_number >> weight;
if (player_number >=1 && player_number <=49)
{
backs ++ ;
backs_weight += weight;
}
else if (player_number >=50 && player_number <=79)
{
linemen ++ ;
linemen_weight += weight;
}
else
{
other ++ ;
other_weight += weight;
}
total_weight += weight;
k--; // Should stop the loop.
}
}
|
With double you will have a more accurate number.
double: 1 / 2 = 0.5
int: 1 / 2 = 0
If you have no division and the accuracy isn't required you can of course use int.
Topic archived. No new replies allowed.