here is solution
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int answer;
int right;
int wrong;
int righta[100];
int wronga[100];
int i;
printf("This is a program of sum\n");
right = 0; /*Initialization of right value*/
wrong = 0; /*Initialization of wrong value*/
for(x = 1; x <= 10; x++)
{
printf("What is %d + %d: ", x, x);
scanf("%d", &answer);
printf("The sum is %d\n", answer);
printf("\a");
if(answer == x + x)
{
printf("%d is RIGHT answer\n", answer);
righta[right]=answer;
right++; /*Saves and increases the amount of right answers*/
}
else
{
printf("%d is WRONG answer\n", answer);
wronga[wrong] = answer;
wrong++; /*Saves and increases th }
}
righta[right]=0;
wronga[wrong]=0;
printf("The right answers are %d and the wrong are %d\n", right, wrong);
printf("The right answers are ");
for(i=0;righta[i];i++){
printf("%d\t",righta[i]);
}
printf("\nThe wrong answers are ");
for(i=0;wronga[i];i++){
printf("%d\t",wronga[i]);
}
fflush(stdin);
getchar();
}
e amount of wrong answers*/
printf("The correct answer is %d\n", x + x);
spiros85 wrote:
Hi guys of dear forum!I am a new programmer in C programming language and i have a question for you about the following C code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int answer;
int right;
int wrong;
printf("This is a program of sum\n");
right = 0; /*Initialization of right value*/
wrong = 0; /*Initialization of wrong value*/
for(x = 1; x <= 10; x++)[QUOTE][/QUOTE]
{
printf("What is %d + %d: ", x, x);
scanf("%d", &answer);
printf("The sum is %d\n", answer);
printf("\a");
if(answer == x + x)
{
printf("%d is RIGHT answer\n", answer);
right++; /*Saves and increases the amount of right answers*/
}
else
{
printf("%d is WRONG answer\n", answer);
b[10] = answer;
wrong++; /*Saves and increases the amount of wrong answers*/
printf("The correct answer is %d\n", x + x);
}
}
printf("The right answers are %d and the wrong are %d\n", right, wrong);
fflush(stdin);
getchar();
}
First, I use DEV C++ compiler!This program asks from user to find the sum of 1+1,2+2 until for loop reaches 10.As you can observe with right++ and wrong++ i can define and print to the screen the amount of right or wrong numbers!
My question is how could I define the number of correct and wrong numbers in collaboration with their amount?For example:
The right answers are 8 and wrong are 2
The right answers are 2 4 6 8 10 12 14 16
The wrong answers are 22 44