У меня есть этот код ниже, который прекрасно работает. Мне просто нужно написать printf как cout. Я пробовал несколько раз, но это ошибки на мне. Любая помощь будет оценена.
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
double mathScores[] = { 95, 87, 73, 82, 92, 84, 81, 76 };
double chemScores[] = { 91, 85, 81, 90, 96, 89, 77, 79 };
double aveScores[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
//calculate size of array
int len = sizeof(mathScores) / sizeof(double);
//use array
for (int i = 0; i < len; ++i) {
aveScores[i] = (mathScores[i] + chemScores[i]) / 2;
}
printf("%s\t%s\t%s\t%s\n", "ID", "math", "chem", "ave");
for (int i = 0; i < len; ++i) {
printf("%d\t%.2f\t%.2f\t%.2f\n", i, mathScores[i], chemScores[i],
aveScores[i]);
}
return 0;
}