| another simple question im still a newbie tryin to learn the basics...
now...
the prob is double & static_cast functions :
int main()
{
int total, // sum of grades
gradeCounter, // number of grades entered
grade; // one grade
double average; // number with decimal point for average
// initialization phase
total = 0;
gradeCounter = 0;
// processing phase
cout << "Enter grade, -1 to end: ";
cin >> grade;
while ( grade != -1 ) {
total = total + grade;
gradeCounter = gradeCounter + 1;
cout << "Enter grade, -1 to end: ";
cin >> grade;
}
// termination phase
if ( gradeCounter != 0 ) {
average = static_cast< double >( total ) / gradeCounter;
cout << "Class average is " << setprecision( 2 )
<< setiosflags( ios::fixed | ios::showpoint )
<< average << endl;
why -> total <- is in parantheses @ average = static_cast< double >( total ) / gradeCounter;
and is there any connection between double and static_cast??
cuz when i tried a proggie with double...
for example the prog was 11/2
and it showed the result as 5 or 6 (i dont remember well)
and when i tried with static_cast as extra , it showed result as 5.5
an explanation can be so nice friends....
and sorry for asking dumbish questions... |