[c] kalkulator macierzy

kawafis44
Użytkownik
Użytkownik
Posty: 474
Rejestracja: 22 paź 2007, o 20:55
Płeć: Mężczyzna
Lokalizacja: Gliwice
Podziękował: 416 razy
Pomógł: 2 razy

[c] kalkulator macierzy

Post autor: kawafis44 »

piszę kalkulator macierzy. gdy wybiorę opcję a, powinien pokazać mi, że nie posiadam żadnych macierzy "You do not own any matrix", ale wyświela mi "You own these matrices: ".
gdzie jest błąd?
pozdrawiam!

Kod: Zaznacz cały

#include <stdio.h>
//#include <cstdlib.h> //library for cleaning the screen

int owned_matrices[27];

char choose_opt()
{
   char temp_opt;
   system("cls"); 
   printf("Matrix calculator
   (a) Create new matrix
   (b) Edit existing matrix
   (c) Show existing matrix
   (d) Delete existing matrix
   (e) Save matrices to the file
   (f) Load matrices from the file
   (g) Transposition (MxN)^T = (NxM)
   (h) Addition (MxN)+(MxN)=(MxN)
   (i) Scalar multiplication c*(MxN)=(MxN)
   (j) Matrix multiplication (MxN)x(NxP)=(MxP)
   (k) Exponentiation (MxM)^c=(MxM)
   (l) Determinant det[(MxM)]=c
   (m) Inverse (MxM)^(-1)=(MxM) if det[(MxM)]<>0
   (n) About the program
   (o) Exit the application\n");
   do
   {
      printf("Choose your option.");
      temp_opt = getch();
      if ((temp_opt < 'a')||(temp_opt > 'o'))
         printf("\nImproper choice. ");
      else
         printf("\n");
   } while ((temp_opt < 'a')||(temp_opt > 'o'));
   return temp_opt;
}

void Show_owned()
{
   int i;
   int do_you_own_any_matrix=0; //check wheter there are any owned matrices
   for (i=1;i<=26;i++)
   {
      if (owned_matrices[i]==1)
         {
            do_you_own_any_matrix=1;
            break;
         }
   }
   if (do_you_own_any_matrix = 1) //if there are, show which one
   {
      printf("You own these matrices: ");
      for (i=1;i<=26;i++)
         {
         if (owned_matrices[i]==1)
            printf("%c",'a'+i-1);
         }
   }
   else
      printf("You do not own any matrix.");
}

void Func_a()
{
   Show_owned();

}

int main(int argc, char *argv[])
{
   char chosen_opt;

   int i; //give the information that there are no owned matrices
   for (i=1;i<=26;i++)
      owned_matrices[i]=0;

   do     //choose the operation on matrix
   {
      chosen_opt = choose_opt();
      printf("Your choice: %c\n",chosen_opt);
      switch (chosen_opt)
      {
         case 'a': Func_a(); break;
         case 'o': printf("See you later!"); break;
         default : printf("Under construction"); break;
      }
      printf("\n");
      getch();
   } while (chosen_opt!='o');

   return 0;
}
Ostatnio zmieniony 29 gru 2007, o 17:20 przez kawafis44, łącznie zmieniany 1 raz.
soku11
Użytkownik
Użytkownik
Posty: 6607
Rejestracja: 16 sty 2007, o 19:42
Płeć: Mężczyzna
Podziękował: 119 razy
Pomógł: 1823 razy

[c] kalkulator macierzy

Post autor: soku11 »

Kod: Zaznacz cały

#include <stdio.h>
//#include <cstdlib.h> //library for cleaning the screen

int owned_matrices[27];

char choose_opt()
{
   char temp_opt;
   
   system("cls");
   printf("Matrix calculator \n\
   (a) Create new matrix \n\
   (b) Edit existing matrix \n\
   (c) Show existing matrix \n\
   (d) Delete existing matrix \n\
   (e) Save matrices to the file \n\
   (f) Load matrices from the file \n\
   (g) Transposition (MxN)^T = (NxM) \n\
   (h) Addition (MxN)+(MxN)=(MxN) \n\
   (i) Scalar multiplication c*(MxN)=(MxN) \n\
   (j) Matrix multiplication (MxN)x(NxP)=(MxP)\n\
   (k) Exponentiation (MxM)^c=(MxM) \n\
   (l) Determinant det[(MxM)]=c\n\
   (m) Inverse (MxM)^(-1)=(MxM) if det[(MxM)]<>0\n\
   (n) About the program\n\
   (o) Exit the application\n");
   
   do
   {
      printf("Choose your option.");
      temp_opt = getch();
      if ((temp_opt < 'a')||(temp_opt > 'o'))
         printf("\nImproper choice. ");
      else
         printf("\n");
   } while ((temp_opt < 'a')||(temp_opt > 'o'));
   return temp_opt;
}

void Show_owned()
{
   int i;
   int do_you_own_any_matrix=0; //check wheter there are any owned matrices
   for (i=0;i<27;i++)
    if (owned_matrices[i])
         {
            do_you_own_any_matrix=1;
            break;
         }
         
   if (do_you_own_any_matrix) //if there are, show which one
   {
      printf("You own these matrices: ");
      for (i=0;i<27;i++)
         {
         if (owned_matrices[i]==1)
            printf("%c",'a'+i-1);
         }
   }
   else
      printf("You do not own any matrix.");
}

void Func_a()
{
   Show_owned();

}

int main(int argc, char *argv[])
{
   char chosen_opt;

   int i; //give the information that there are no owned matrices
   for (i=0;i<27;i++)
      owned_matrices[i]=0;

   do     //choose the operation on matrix
   {
      chosen_opt = choose_opt();
      printf("Your choice: %c\n",chosen_opt);
      switch (chosen_opt)
      {
         case 'a': Func_a(); break;
         case 'o': printf("See you later!"); break;
         default : printf("Under construction"); break;
      }
      printf("\n");
      getch();
   } while (chosen_opt!='o');

   return 0;
}
Ja to widze tak... Tylko nie wiem czemu indeksujesz sobie tablice od 1 :/ POZDRO
ODPOWIEDZ