Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

problem with C++ programming.These question is about to read a some information

ID: 3761894 • Letter: P

Question

problem with C++ programming.These question is about to read a some information from a file about the power plant data.

write a program to print the day of the week and the number of the week on which the minimum power output occurred. If there are several days with the minimum power output, print the information for each of these days.

this is my code.

#include <iostream>
#include <fstream>
using namespace std;

int main() {
   int minimum_power=1000;
   int r, c;
   int output_power[10][7];
   ifstream power;
   power.open("power1.dat");
   if (power.fail()) {
       cerr << "faile power1.dat could not be opened.";
           exit(1);

   }
   for (r = 0; r < 10; r++) {
       for (c = 0; c < 7; c++) {
           power >> output_power[r][c];
           if (output_power[r][c] < minimum_power) {
               minimum_power = output_power[r][c];
               cout << output_power[r][c];
           }
       }
   }
   cout << "minimum power output was:" << minimum_power << endl;
   for (r = 0; r < 10; r++) {
       for (c = 0; c < 7; c++) {
           if (output_power[r][c] == minimum_power) {
               cout << "week " << r << ",day " << c << "was a minimum power out day." << endl;
           }
       }
   }
   return 0;
}

however, it cannot work correctly.

can somebody post the correct code for me, or helpful answer is acceptable.

Explanation / Answer

Program code:

// powerplant.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

#include <fstream>

using namespace std;

int main() {

   int minimum_power=1000;

   int r, c;

   int output_power[8][7];//modify the array size

   ifstream power;

   power.open("E:/power1.dat");// location of the file changed

   if (power.fail()) {

       cerr << "faile power1.dat could not be opened.";

           exit(1);

   }

   for (r = 0; r <8; r++)//modfiy the condition statement in for loop based on the array size.

   {

       for (c = 0; c<7; c++)

               {

           power >> output_power[r][c];

           if (output_power[r][c] < minimum_power) {

               minimum_power = output_power[r][c];

              // cout << output_power[r][c];//not need to print this output.

           }

       }

   }

   cout << "minimum power output was:" << minimum_power << endl;

   for (r = 0; r<8; r++)//modfiy the condition statement in for loop based on the array size.

   {

{

       for (c = 0; c<7; c++) {

           if (output_power[r][c] == minimum_power)

                           {

               cout << "week " << r+1 << ",day " << c+1 << "was a minimum power out day." << endl; // week number and day number are printed exactly with this statement.

           }

       }

   }

   system("pause");

   return 0;

}

Sample output: