-2
/*This code creates two text files : Mokiniai.txt and Vidurkiai.txt
In Mokiniai.txt there are stored each students grades, in Vidurkiai there
should be calculated each students average grade*/
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n, k, isvisopazymiu, i, pazymiai;
double vidurkis; //average grade
ofstream myfile;
myfile.open("Mokiniai.txt");
cout << "parasykite kiek mokiniu yra" << endl; cin >> n; //how many students
myfile << n << endl;
cout << "parasykite kiek yra mokiniu pazymiu"; cin >> isvisopazymiu; // how many grades one student has
for (k = 1; k <= n; k++) {
for (i = 1; i <= isvisopazymiu; i++) {
cout << "Parasykite kokie yra mokiniu pazymiai "; cin >> pazymiai; // what are students grades
myfile << " " << pazymiai;
}
myfile << endl;
}
myfile.close();
myfile.open("Vidurkiai.txt"); //trying to calculate average students grades on different file
for (k = 1; k <= n; k++) {
vidurkis = pazymiai/isvisopazymiu; //calculating students grades
myfile << k << " " << vidurkis << endl;
}
myfile.close();
return 0;
}
私の問題は:vidurkiai.txtファイルに何か問題がありますが、何が間違っているのか分かりません。例えば私は各学生の平均等級を計算する必要があります
:7 8 9 7 8、及び平均等級は7.8でなければならないが、それを符号化した後、vidurkiai.txtファイルには、平均的なグレード1
を使用しながら、これは宿題のように見えるよう
... – Charles
あなたのコードをステップ実行するためにデバッガを使用する方法を学ぶ必要があるかもしれないように聞こえます。良いデバッガを使用すると、プログラムを1行ずつ実行し、どこからずれているかを確認することができます。これはプログラミングをする場合に不可欠なツールです。さらに読む:** [小さなプログラムをデバッグする方法](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver
@ c650はい、それは私の宿題です: Dでも、まだまだ...私はそれにいくつかの問題があります – loneperv