I have a c++ code here. This code is to calculate data inside some files.
#include<stdio.h> #include<iostream> #include <fstream> using namespace std; int main(){ //initiate file variable ifstream inFile; //other variable int count, limit=30, time, remain, flag=0, time_quantum, arrival_time=30, var, total_process[30], data; int wait_time=0, turnaround_time=0, rt[30], num_of_interrupts=0, num_of_jobs=0; cout<<"Your job list :\n"; for(var = 1; var <= limit; var++){ //the purpose is the check weither looping is okay or not cout<<""<<var; //preparing array for the file char nambuf[30]; std::snprintf(nambuf, sizeof(nambuf), "job%d.txt", var); std::ifstream inFile; //open file inFile.open(nambuf); //check file if (!inFile) { cout << " Unable to open file"; exit(1); // terminate with error } //read data from file .txt while (inFile >> data) { //calculate total process from data total_process[var] += data; ++data; } //close file inFile.close(); //print total process cout << " Sum = " << total_process[var] << endl; } return 0; }
The code was run as it supposed. But the problem occur after performing total process calculation. Example of output :
Sorry if the code was not good in design. I'm still new in programming.