Need help with a C problem I only need Problem 22 the very l

Need help with a C++ problem. I only need Problem 2-2 the very last one just checking bounds and correcting errors. Here is the instructions: http://docdro.id/doXfQVc

Here is some of it I did. http://pastebin.com/dpxjNNdm

Solution

Code:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
   ifstream ifile;
   ifile.open(\"imagedata.txt\");
   int a[20][20];
   char b[20][20];

   for (int i = 0;i < 20;i++)
   {
       for (int j = 0;j < 20;j++)
       {
           ifile >> a[i][j];
       }
   }

   for (int i = 0;i < 20;i++)
   {
       int up,down,left,right,average;
       for (int j = 0;j < 20;j++)
       {
          if(i-1>=0)
          {
              up=a[i-1][j];
              if(i+1<20)
              {
               down=a[i+1][j];
               if(j-1>=0)
               {
                   left=a[i][j-1];
                   if(j+1<20)
                   {
                       right=a[i][j+1];
                       if(abs(a[i][j]-up) >1 || abs(a[i][j]-down) >1 || abs(a[i][j]-left) >1 || abs(a[i][j]-down) >1 )
                       {
                          float avg=(up+down+left+right)/4;
                       int upper=(int)avg+1;
                          int lower=(int)avg;
                          if(((float)upper-avg)>(avg-(float)lower))
                          {
                              average=lower;
                          }
                          else
                          {
                              average=upper;
                          }
                          a[i][j]=average;
                      
                       }
                   }


               }
              }
           }
      

       }
   }

   for (int i = 0;i < 20;i++)
   {
       for (int j = 0;j < 20;j++)
       {
           b[i][j] = a[i][j];
           if (a[i][j] >= 5)
               b[i][j] = \'$\';
           else if (a[i][j] >= 2 && a[i][j] <= 4)
               b[i][j] = \'*\';
           else if (a[i][j] <= 1)
               b[i][j] = \' \';
       }
   }
   for (int i = 0;i < 20;i++)
   {
       for (int j = 0;j < 20;j++)
       {
           cout << b[i][j];
       }
       cout << \"\ \";
   }
   cout << endl << endl;
   system(\"pause\");
   return 0;
}

Need help with a C++ problem. I only need Problem 2-2 the very last one just checking bounds and correcting errors. Here is the instructions: http://docdro.id/d
Need help with a C++ problem. I only need Problem 2-2 the very last one just checking bounds and correcting errors. Here is the instructions: http://docdro.id/d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site