Apr 24, 2010 at 12:24pm UTC
Some part of 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 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
for (int i = 0; i < numLes; i++) {
char not[3] = "XX" ;
char *ptr = not;
if (marks[i] == 0) {
*ptr = 'F' ;
*ptr++;
*ptr = 'F' ;
}else if (marks[i] == 1.5) {
*ptr = 'F' ;
*ptr++;
*ptr = 'D' ;
}else if (marks[i] == 3) {
*ptr = 'D' ;
*ptr++;
*ptr = 'D' ;
}else if (marks[i] == 4.5) {
*ptr = 'D' ;
*ptr++;
*ptr = 'C' ;
}else if (marks[i] == 6) {
*ptr = 'C' ;
*ptr++;
*ptr = 'C' ;
}else if (marks[i] == 7.5) {
*ptr = 'C' ;
*ptr++;
*ptr = 'B' ;
}else if (marks[i] == 9) {
*ptr = 'B' ;
*ptr++;
*ptr = 'B' ;
}else if (marks[i] == 10.5) {
*ptr = 'B' ;
*ptr++;
*ptr = 'A' ;
}else if (marks[i] == 12) {
*ptr = 'A' ;
*ptr++;
*ptr = 'A' ;
}
cout << setw(22) << right << lessons[i] << "\t" << setw(10) << not << setw(12) << right << marks[i] << "\n" << endl;
total += marks[i];
}
In visual c++ it compiles and works but in devc++ it gives this output
29 C:\Dev-Cpp\pro\ders\main.cpp expected primary-expression before "char"
29 C:\Dev-Cpp\pro\ders\main.cpp expected `;' before "char"
30 C:\Dev-Cpp\pro\ders\main.cpp expected primary-expression before ';' token
30 C:\Dev-Cpp\pro\ders\main.cpp expected primary-expression before ';' token
87 C:\Dev-Cpp\pro\ders\main.cpp expected primary-expression before '<<' token
What is a primary expression
Last edited on Apr 24, 2010 at 12:40pm UTC
Apr 24, 2010 at 2:47pm UTC
Also, don't use == with floating ponits. It will often produce "incorrect" results.
Remembrer floating points are an approximation, not the exact value. So 1.5 doesn't necessarily equal 1.5.