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

This is a simple program that searches for a number in an arrayalready created b

ID: 3616664 • Letter: T

Question

This is a simple program that searches for a number in an arrayalready created but i am having problems with the while loop im notsure if its syntax errors, i will rate your answer thank you.


#include <iostream>
using namespace std;
int main()
{
   //declaring variables
   int mat [3][3];
   int n;
   int row;
   int col;
   int item;
   int loc;
   n=3;
   //creating a matrix
   mat [0][0]=45;
   mat [0][1]=77;
   mat [0][2]=93;
   mat [1][0]=78;
   mat [1][1]=79;
   mat [1][2]=85;
   mat [2][0]=72;
   mat [2][1]=96;
   mat [2][2]=77;
   cout<<"enter the number you wish to searchfor: ";
   cin>>item;
       
   //searching for item in the matrix



bool found;

   found=false;
   row=0;
   col=0;
  
while(row<n;col<n)&&(not found)
   {
   if (mat[row][col]==item)
   {
   found=true;
   loc=[row][col];
   }
   else (row++)&&(col++);
   }
  
if (found)
               cout<<"item found ";
else
               cout<<"item not found ";

            
   cout<<"the number its locatedin"<<loc<<endl;
    return 0;
}

Explanation / Answer

You have to write it like while( row
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote