Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I can't compile and put it as a variable and matrix

I can't compile and put it as a variable and matrix

Scheduled Pinned Locked Moved C / C++ / MFC
help
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14984894
    wrote on last edited by
    #1

    Hi! I cannot compile this program. Please help me because I have no idea how I do it, my teacher spent this activity and I found it very difficult. After completing an option, the program must return to the initial menu until "0" is pressed.

    #include #include int main()
    {
    system("CLS");
    int item [8][5]; // matrix that will store how many items have been released
    int op,vaga,i,j;
    float value[8][5]; //matrix that will store the total value
    float box = 0; /// variable that will store the value of the box

    printf("\n");
    printf ("|*--------------------Welcome to the restaurant! -------------------- *|\n");
    printf("\n");

    			//Menu
    

    printf(" [1] Open table\n");
    printf(" [2] Launch expense\n");
    printf(" [3] Close table account\n");
    printf(" [4] Check Cashier\n");
    printf(" [0] Exit\n");
    printf("\n Choose an option:");
    scanf ("%d",&op);
    switch (op)
    // should receive only one character which are the (1,2,3,4,0) without the need to prefix the enter any other number should be disregarded.
    {
    case 0:
    printf("Leaving the Program");
    break;
    case 1:
    printf ("Enter table number:");
    scanf("%d");
    if (item>=-1) printf("%d table open");
    else if (item<= 0)
    printf("Error that table is not free. Choose another table!");
    function_open_table();
    break;
    case 2:
    printf("Value launched on table");
    printf("Placement amount: %d");
    scanf("%d");
    printf("Total value of the table:R$ ");
    scanf("%f");
    if (table>=-0) printf("%d table open");
    else if (table<= -1)
    printf("Error that table is not open!");
    function_Launch_dispatch();
    break;
    case 3:
    printf("The table has just been closed");
    // the total value of the table and the amount of posted items that are in (case 2) appear
    break;
    case 4:
    printf("The total value in the box: R$%.2f");
    // the total value of the box of all the tables
    break;
    default:
    printf("option invalidates!");
    }
    return 0;
    }

    V J M 3 Replies Last reply
    0
    • M Member_14984894

      Hi! I cannot compile this program. Please help me because I have no idea how I do it, my teacher spent this activity and I found it very difficult. After completing an option, the program must return to the initial menu until "0" is pressed.

      #include #include int main()
      {
      system("CLS");
      int item [8][5]; // matrix that will store how many items have been released
      int op,vaga,i,j;
      float value[8][5]; //matrix that will store the total value
      float box = 0; /// variable that will store the value of the box

      printf("\n");
      printf ("|*--------------------Welcome to the restaurant! -------------------- *|\n");
      printf("\n");

      			//Menu
      

      printf(" [1] Open table\n");
      printf(" [2] Launch expense\n");
      printf(" [3] Close table account\n");
      printf(" [4] Check Cashier\n");
      printf(" [0] Exit\n");
      printf("\n Choose an option:");
      scanf ("%d",&op);
      switch (op)
      // should receive only one character which are the (1,2,3,4,0) without the need to prefix the enter any other number should be disregarded.
      {
      case 0:
      printf("Leaving the Program");
      break;
      case 1:
      printf ("Enter table number:");
      scanf("%d");
      if (item>=-1) printf("%d table open");
      else if (item<= 0)
      printf("Error that table is not free. Choose another table!");
      function_open_table();
      break;
      case 2:
      printf("Value launched on table");
      printf("Placement amount: %d");
      scanf("%d");
      printf("Total value of the table:R$ ");
      scanf("%f");
      if (table>=-0) printf("%d table open");
      else if (table<= -1)
      printf("Error that table is not open!");
      function_Launch_dispatch();
      break;
      case 3:
      printf("The table has just been closed");
      // the total value of the table and the amount of posted items that are in (case 2) appear
      break;
      case 4:
      printf("The total value in the box: R$%.2f");
      // the total value of the box of all the tables
      break;
      default:
      printf("option invalidates!");
      }
      return 0;
      }

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      What error(s) do you get from the compiler?

      1 Reply Last reply
      0
      • M Member_14984894

        Hi! I cannot compile this program. Please help me because I have no idea how I do it, my teacher spent this activity and I found it very difficult. After completing an option, the program must return to the initial menu until "0" is pressed.

        #include #include int main()
        {
        system("CLS");
        int item [8][5]; // matrix that will store how many items have been released
        int op,vaga,i,j;
        float value[8][5]; //matrix that will store the total value
        float box = 0; /// variable that will store the value of the box

        printf("\n");
        printf ("|*--------------------Welcome to the restaurant! -------------------- *|\n");
        printf("\n");

        			//Menu
        

        printf(" [1] Open table\n");
        printf(" [2] Launch expense\n");
        printf(" [3] Close table account\n");
        printf(" [4] Check Cashier\n");
        printf(" [0] Exit\n");
        printf("\n Choose an option:");
        scanf ("%d",&op);
        switch (op)
        // should receive only one character which are the (1,2,3,4,0) without the need to prefix the enter any other number should be disregarded.
        {
        case 0:
        printf("Leaving the Program");
        break;
        case 1:
        printf ("Enter table number:");
        scanf("%d");
        if (item>=-1) printf("%d table open");
        else if (item<= 0)
        printf("Error that table is not free. Choose another table!");
        function_open_table();
        break;
        case 2:
        printf("Value launched on table");
        printf("Placement amount: %d");
        scanf("%d");
        printf("Total value of the table:R$ ");
        scanf("%f");
        if (table>=-0) printf("%d table open");
        else if (table<= -1)
        printf("Error that table is not open!");
        function_Launch_dispatch();
        break;
        case 3:
        printf("The table has just been closed");
        // the total value of the table and the amount of posted items that are in (case 2) appear
        break;
        case 4:
        printf("The total value in the box: R$%.2f");
        // the total value of the box of all the tables
        break;
        default:
        printf("option invalidates!");
        }
        return 0;
        }

        J Offline
        J Offline
        jeron1
        wrote on last edited by
        #3

        At a quick glance, you have this

        scanf ("%d",&op);

        and you have this

        scanf("%d");

        the second one is missing the variable where you want the data to go. Similarly with the printf() statements

        printf("Placement amount: %d");

        you're specifying an integer to be output with the %d, there isn't a corresponding value.

        printf("Placement amount: %d", value); //<== value to print

        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

        1 Reply Last reply
        0
        • M Member_14984894

          Hi! I cannot compile this program. Please help me because I have no idea how I do it, my teacher spent this activity and I found it very difficult. After completing an option, the program must return to the initial menu until "0" is pressed.

          #include #include int main()
          {
          system("CLS");
          int item [8][5]; // matrix that will store how many items have been released
          int op,vaga,i,j;
          float value[8][5]; //matrix that will store the total value
          float box = 0; /// variable that will store the value of the box

          printf("\n");
          printf ("|*--------------------Welcome to the restaurant! -------------------- *|\n");
          printf("\n");

          			//Menu
          

          printf(" [1] Open table\n");
          printf(" [2] Launch expense\n");
          printf(" [3] Close table account\n");
          printf(" [4] Check Cashier\n");
          printf(" [0] Exit\n");
          printf("\n Choose an option:");
          scanf ("%d",&op);
          switch (op)
          // should receive only one character which are the (1,2,3,4,0) without the need to prefix the enter any other number should be disregarded.
          {
          case 0:
          printf("Leaving the Program");
          break;
          case 1:
          printf ("Enter table number:");
          scanf("%d");
          if (item>=-1) printf("%d table open");
          else if (item<= 0)
          printf("Error that table is not free. Choose another table!");
          function_open_table();
          break;
          case 2:
          printf("Value launched on table");
          printf("Placement amount: %d");
          scanf("%d");
          printf("Total value of the table:R$ ");
          scanf("%f");
          if (table>=-0) printf("%d table open");
          else if (table<= -1)
          printf("Error that table is not open!");
          function_Launch_dispatch();
          break;
          case 3:
          printf("The table has just been closed");
          // the total value of the table and the amount of posted items that are in (case 2) appear
          break;
          case 4:
          printf("The total value in the box: R$%.2f");
          // the total value of the box of all the tables
          break;
          default:
          printf("option invalidates!");
          }
          return 0;
          }

          M Offline
          M Offline
          Member_14984894
          wrote on last edited by
          #4

          I managed to compile only that now what I'm having difficulty is to make the program return to the menu at the end of the command so that new commands are given and the values ​​are saved in the box. (I'm sorry if my English is bad, I am translating to clear my doubts here.)

          #include #include int main()
          {
          int item [8][5]; // matrix that will store how many items have been released
          int i,j,op;
          float value[8][5]; //matrix that will store the total value
          float box = 0; /// variable that will store the value of the box
          int table();

          printf("\n");
          printf ("|*--------------------"|- Welcome to the restaurant! -------------------- *|\n");
          printf("\n");
          //Menu
          printf(" [1] Open table\n");
          printf(" [2] Launch expense\n");
          printf(" [3] Close table account\n");
          printf(" [4] Check Cashier\n");
          printf(" [0] Exit\n");
          printf("\n Choose an option:");
          scanf ("%d",&op);
          switch (op)
          // should receive only one character which are the (1,2,3,4,0) without the need to press the enter any other number should be disregarded.
          {
          case 0:
          printf("Leaving");
          break;

          case 1:

          printf ("Enter table number: ");
          scanf ("%d",&i,&j);

          if (item <=-1) //item=-1 closed table
          printf("open table %d \n ",i,j);
          else //////
          if (item>=0) //item =0 closed table
          printf("This table is not free. Choose another table!");
          break;

          case 2:
          printf ("Enter table number:");
          scanf ("%d",&i,&j);
          if (item <=0) //item =0 open table
          printf ("Enter with the value to be launched on the table %d: R$ \n ",i,j);
          scanf ("%.2f",&i,&j,&value);
          printf(" Value launched on the table.\n ");
          printf("Amount posted: \n"); // show how many postings were on the table
          printf(" Total table value: %.2f \n",value);

          (item >=-1);
          printf(" Error: This table is not open! \n"); //item=-1 table closed

          break;
          case 3:
          printf ("Enter table number:");
          scanf ("%d",&i,&j);

          printf(" The table has just been closed \n");
          printf(" Amount of postings: \n"); // show how many postings you had on the table
          printf(" Total value of the table %d e' R$ %.2f \n",i,j,value);

          	   break;
              case 4: 
                  printf("The total value in the box: R$"); // should show the total value you have in the box of all tables that have already been opened
                   scanf("%f",&box);                                                
          	    break;
          

          }
          return 0;
          }

          J 1 Reply Last reply
          0
          • M Member_14984894

            I managed to compile only that now what I'm having difficulty is to make the program return to the menu at the end of the command so that new commands are given and the values ​​are saved in the box. (I'm sorry if my English is bad, I am translating to clear my doubts here.)

            #include #include int main()
            {
            int item [8][5]; // matrix that will store how many items have been released
            int i,j,op;
            float value[8][5]; //matrix that will store the total value
            float box = 0; /// variable that will store the value of the box
            int table();

            printf("\n");
            printf ("|*--------------------"|- Welcome to the restaurant! -------------------- *|\n");
            printf("\n");
            //Menu
            printf(" [1] Open table\n");
            printf(" [2] Launch expense\n");
            printf(" [3] Close table account\n");
            printf(" [4] Check Cashier\n");
            printf(" [0] Exit\n");
            printf("\n Choose an option:");
            scanf ("%d",&op);
            switch (op)
            // should receive only one character which are the (1,2,3,4,0) without the need to press the enter any other number should be disregarded.
            {
            case 0:
            printf("Leaving");
            break;

            case 1:

            printf ("Enter table number: ");
            scanf ("%d",&i,&j);

            if (item <=-1) //item=-1 closed table
            printf("open table %d \n ",i,j);
            else //////
            if (item>=0) //item =0 closed table
            printf("This table is not free. Choose another table!");
            break;

            case 2:
            printf ("Enter table number:");
            scanf ("%d",&i,&j);
            if (item <=0) //item =0 open table
            printf ("Enter with the value to be launched on the table %d: R$ \n ",i,j);
            scanf ("%.2f",&i,&j,&value);
            printf(" Value launched on the table.\n ");
            printf("Amount posted: \n"); // show how many postings were on the table
            printf(" Total table value: %.2f \n",value);

            (item >=-1);
            printf(" Error: This table is not open! \n"); //item=-1 table closed

            break;
            case 3:
            printf ("Enter table number:");
            scanf ("%d",&i,&j);

            printf(" The table has just been closed \n");
            printf(" Amount of postings: \n"); // show how many postings you had on the table
            printf(" Total value of the table %d e' R$ %.2f \n",i,j,value);

            	   break;
                case 4: 
                    printf("The total value in the box: R$"); // should show the total value you have in the box of all tables that have already been opened
                     scanf("%f",&box);                                                
            	    break;
            

            }
            return 0;
            }

            J Offline
            J Offline
            jeron1
            wrote on last edited by
            #5

            To return to the menu I'd imagine that you would need some type of loop construct, like a while() loop, or a do-while loop. Your formatted inputs and outputs don't look right;

            Member 14984894 wrote:

            scanf ("%d",&i,&j);

            you're asking for a single integer (the '%d'), but you have 2 variables there i and j. What are you expecting to happen? Same goes for some of the printf() statements.

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            M D 2 Replies Last reply
            0
            • J jeron1

              To return to the menu I'd imagine that you would need some type of loop construct, like a while() loop, or a do-while loop. Your formatted inputs and outputs don't look right;

              Member 14984894 wrote:

              scanf ("%d",&i,&j);

              you're asking for a single integer (the '%d'), but you have 2 variables there i and j. What are you expecting to happen? Same goes for some of the printf() statements.

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

              M Offline
              M Offline
              Member_14984894
              wrote on last edited by
              #6

              I left & i, & j because it is the line and the row where the tables will be chosen. I thought that this way I would be storing the tables that were chosen

              J J 2 Replies Last reply
              0
              • M Member_14984894

                I left & i, & j because it is the line and the row where the tables will be chosen. I thought that this way I would be storing the tables that were chosen

                J Offline
                J Offline
                jeron1
                wrote on last edited by
                #7

                You would need something like the following to enter 2 values.

                scanf("%d %d" &i, &j);

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                1 Reply Last reply
                0
                • J jeron1

                  To return to the menu I'd imagine that you would need some type of loop construct, like a while() loop, or a do-while loop. Your formatted inputs and outputs don't look right;

                  Member 14984894 wrote:

                  scanf ("%d",&i,&j);

                  you're asking for a single integer (the '%d'), but you have 2 variables there i and j. What are you expecting to happen? Same goes for some of the printf() statements.

                  "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  While incorrect, I do not think any harm comes from extra parameters in the vararg list (they do not get popped from the stack unless a corresponding % format specifier is present). Had it been something like this instead, then it would be a problem.

                  scanf("%d %d", &i);

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  J 1 Reply Last reply
                  0
                  • D David Crow

                    While incorrect, I do not think any harm comes from extra parameters in the vararg list (they do not get popped from the stack unless a corresponding % format specifier is present). Had it been something like this instead, then it would be a problem.

                    scanf("%d %d", &i);

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    J Offline
                    J Offline
                    jeron1
                    wrote on last edited by
                    #9

                    Very true, I was hoping that the person would scrutinize that line and understand that it probably didn't accomplish what they were trying to do.

                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                    1 Reply Last reply
                    0
                    • M Member_14984894

                      I left & i, & j because it is the line and the row where the tables will be chosen. I thought that this way I would be storing the tables that were chosen

                      J Offline
                      J Offline
                      jsc42
                      wrote on last edited by
                      #10

                      If you want to save the value into an array, you have to say which array and whereabouts in the array you want it to go. My guess is that you want something like

                      scanf("%d", &item[i][j]);

                      [Caveat Emptor: It is several decades since I wrote C programs, so my syntax may be awry]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups