0

please help to with this program by mainly using arrays and pointers ,... i need this program to check 2 matrix files "if they contain any character and if they contain cout<<"invalid"; " and to open them from .txt file

Help with Code Tags
cplusplus Syntax (Toggle Plain Text)

1.
      #include<iostream>
   2.
      #include<fstream>
   3.
      #include<string>
   4.
      #include<cmath>
   5.
      using namespace std;
   6.
       
   7.
      int main()
   8.
      {
   9.
      char y, n;
  10.
      ifstream file1;
  11.
      ifstream file2;
  12.
      string filename1;
  13.
      string filename2;
  14.
      string c;
  15.
      int number;
  16.
      int choice;
  17.
       
  18.
      cout<<"xxxxxxx matrix calculator \n";
  19.
      cout<<"please choose from the following menu :\n";
  20.
       
  21.
      while(choice!=8&&choice==n)
  22.
      {
  23.
      cout<<"1. matrix addition\n";
  24.
      cout<<"2. matrix subtraction\n";
  25.
      cout<<"3. matrix multiplication\n";
  26.
      cout<<"4. matrix transpose\n";
  27.
      cout<<"5. checking matrix equality\n";
  28.
      cout<<"6. check matrix properties\n";
  29.
      cout<<"7. matrix power\n";
  30.
      cout<<"8. exit\n";
  31.
      cout<<"please enter your choice\n";
  32.
      cin>>choice;
  33.
       
  34.
      while(//condition when there is character)// for the first file and the second one :D
  35.
      {
  36.
      cout<<"invalid file!!\n";
  37.
      cout<<"do you want to continue (y) or return to menu(n)\n";
  38.
      /* "y" to continue to try to enter the file name again & "n" to go back to the menu*/
  39.
      cin>>choice1;
  40.
      if(choice1=='y')
  41.
      {
  42.
      cout<<"please enter the first filename\n";
  43.
      cin>>filename1;
  44.
      file1.open(filename1.c_str(),ios::in);
  45.
       
  46.
      if(!file1.fail())
  47.
      {
  48.
      cout<<"good\n";
  49.
      break;
  50.
      }
  51.
      }
  52.
      else if(choice1=='n')
  53.
      {
  54.
      cout<<"assdasdasdad\n";
  55.
      break;
  56.
      }
  57.
      }
  58.
       
  59.
       
  60.
       
  61.
      switch(choice)
  62.
      {
  63.
      case 1 :
  64.
       
  65.
      case 2 :
  66.
       
  67.
      case 3 :
  68.
       
  69.
      case 4 :
  70.
       
  71.
      case 5 :
  72.
       
  73.
      case 6 :
  74.
       
  75.
      case 7 :
  76.
       
  77.
      case 8 :
  78.
      cout<<"thank you for using my program\n";
  79.
      exit(1);
  80.
      }
  81.
       
  82.
      system ("pause");
  83.
      return 0;
  84.
      }
  85.
      }
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

You can use something like if

if (isalpha(a))//Here 'a' is just a variable in which a character is filled in
{
cout<<"Invalid";
}

Youshould include the header cctype for this function. It detects if the input is an alphabet and if it is it executes the statement.

0

It isn't necessary for you to manually put all those line numbers in your code -- the code tags will do that for you.

This tells you to use code tags - http://www.daniweb.com/forums/forum2.html
So does this - http://www.daniweb.com/forums/forum8.html
Wait for it, wait for it - http://www.daniweb.com/forums/announcement8-3.html
You're not going to believe this - http://www.daniweb.com/forums/thread78223.html
And not forgetting the watermark at the back of the edit window.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.