Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to check for all true or false how many are correct answers 5/5

+4 votes
asked Feb 22, 2022 by Rohit sharma (160 points)
#include <stdio.h>

int main ()
{
  int d, a;
  printf ("enter sum of 5+5\n");
  scanf ("%d", &d);

  if (d == 10)
    {
      printf ("true\n");

    }
  else
    {
      printf ("false\n");
    }

  printf ("multiple of 5*5 is ");
  scanf ("%d", &d);
  if (d == 25)
    {
      printf ("true\n");

    }
  else
    {
      printf ("false\n");
    }

  printf ("6 divided by 2 is\n");
  scanf ("%d", &d);
  if (d == 3)
    {
      printf ("true\n");

    }
  else
    {
      printf ("false\n");
    }

  printf ("sum of 18 + 18 is ");
  scanf ("%d", &d);
  if (d == 36)
    {
      printf ("true\n");

    }
  else
    {
      printf ("false\n");
    }

  printf ("multiple of 3*3 is ");
  scanf ("%d", &d);
  if (d == 9)
    {
      printf ("true\n");

    }
  else
    {
      printf ("false\n");
    }

  return 0;
}

1 Answer

+2 votes
answered Feb 23, 2022 by Peter Minarik (86,180 points)
edited Feb 23, 2022 by Peter Minarik

You can add a new variable and keep incrementing it every time the user answers correctly.

int correctAnswers = 0;
// ...
if ([correct answer])
{
    printf("true\n");
    correctAnswers++;
}
// ...
printf("Correctly answered: %d", correctAnswers);
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...