|
|
back to boardWA4 Can anyone help me with test 4? #include <iostream> #include <cstdio> using namespace std; int main() { char c[3]; float v[3]; float R = 8.314, p, V, T, n; scanf("%c = %f\n", &c[0], &v[0]); scanf("%c = %f\n", &c[1], &v[1]); scanf("%c = %f", &c[2], &v[2]); for(int i = 0; i < 3; i++) { if(c[i] == 'p') p = v[i]; else if(c[i] == 'V') V = v[i]; else if(c[i] == 'T') T = v[i]; else if(c[i] == 'n') n = v[i]; } if(c[0] != 'n' && c[1] != 'n' && c[2] != 'n') { n = p*V/(R*T); if(T == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || T < 0 || n < 0) cout << "error\n"; else printf("n = %f\n", n); } else if(c[0] != 'T' && c[1] != 'T' && c[2] != 'T') { T = p*V/(R*n); if(n == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(n == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("T = %f\n", T); } else if(c[0] != 'V' && c[1] != 'V' && c[2] != 'V') { V = n*T*R/p; if(p == 0 && (T == 0 || n == 0)) cout << "undefined\n"; else if(p == 0 && (T != 0 || n != 0)) cout << "error\n"; else if(p < 0 || T < 0 || n < 0 || V < 0) cout << "error\n"; else printf("V = %f\n", V); } else if(c[0] != 'p' && c[1] != 'p' && c[2] != 'p') { p = n*T*R/V; if(T == 0 && (n == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (n != 0 || V != 0)) cout << "error\n"; else if(V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("p = %f\n", p); } return 0; } |
|
|