solve this.....

guys please check this code and tell me why the hell this is not working?
Question is-a test consisting of 10 multiple choice ques is administered to a batch of two students.first we input correct options on terminal like(abcdeabcde) and then students answers respectively.
and will got result for each ques.



but this code is not working....
/*............................STARTING OF CODE...................*/




#include
#include
#include
#define QUES 10
#define STUD 2
/* COADED BY NIKHIL SAGAR */
void main()
{
int i;
char answer[QUES],choice[QUES];
printf ("please enter answer keys

");
for (i=1;i<=QUES;i++)
{
scanf ("%c",&answer[i]);
}

for (i=1;i<=STUD;i++)
{
printf ("Please enter Student No. %d's Choices

",i);
for (i=1;i<=QUES;i++)
{
scanf ("%c",&choice[i]);
}
for (i=1;i<=QUES;i++)
{
if (answer[i]==choice[i])
{ printf ("Ques Number %d is CORRECT
",i); }
else
printf ("Ques Number %d is WRONG
",i);
}
}
getch();
system("cls");
/* COADED BY NIKHIL SAGAR */
}





/*........................END OF CODE.........................*/


i have a code for the same problem and that one is working very fine but that is huge.and also i would like to know the error of this code too.

Comments

  • If you have a variable [b]answer[10][/b], you need to index it from [b]0[/b] to [b]9[/b] (not 1 to 10).

  • [color=Purple]: If you have a variable [b]answer[10][/b], you need to index it from
    : [b]0[/b] to [b]9[/b] (not 1 to 10).[/color]
    :
    :
    thanks for reply dude.....
    what if i edit this.....

    [color=Red]:char answer[QUES],choice[QUES];
    [/color]

    to this....

    [color=Red]:char answer[QUES+1],choice[QUES+1];[/color]

    ithink it is ok by you.....if yes then run it and it is also giving runtime error......dude if you can write this code correctly i mean without runtime/compile time error then please post here as soon as possible....thanks in advance....
  • [color=Purple]: If you have a variable [b]answer[10][/b], you need to index it from
    : [b]0[/b] to [b]9[/b] (not 1 to 10).[/color]
    :
    :
    thanks for reply dude.....
    what if i edit this.....

    [color=Red]:char answer[QUES],choice[QUES];
    [/color]

    to this....

    [color=Red]:char answer[QUES+1],choice[QUES+1];[/color]

    ithink it is ok by you.....if yes then run it and it is also giving runtime error......dude if you can write this code correctly i mean without runtime/compile time error then please post here as soon as possible....thanks in advance....
  • [color=Purple]: If you have a variable [b]answer[10][/b], you need to index it from
    : [b]0[/b] to [b]9[/b] (not 1 to 10).[/color]
    :
    :
    thanks for reply dude.....
    what if i edit this.....

    [color=Red]:char answer[QUES],choice[QUES];
    [/color]

    to this....

    [color=Red]:char answer[QUES+1],choice[QUES+1];[/color]

    ithink it is ok by you.....if yes then run it and it is also giving runtime error......dude if you can write this code correctly i mean without runtime/compile time error then please post here as soon as possible....thanks in advance....

  • Yes, that looks like it will work. But you would be wasting array entry 0. Also, it would be an invitation for someone in the future to misunderstand the code and make an error when trying to modify it.

    So instead of looping like this: [code]for (i=1; i<=QUES; i++)[/code]
    you should do it the more standard and common way, like this: [code]for (i=0; i<QUES; i++)[/code]
  • :
    : Yes, that looks like it will work. But you would be wasting array
    : entry 0. Also, it would be an invitation for someone in the future
    : to misunderstand the code and make an error when trying to modify it.
    :
    : So instead of looping like this: [code]: for (i=1; i<=QUES; i++)[/code]:
    : you should do it the more standard and common way, like this: [code]: for (i=0; i<QUES; i++)[/code]:
    :


    yeah thx for suggestion dude but after this modification it is still not working and giving logical errors.....check it out on your machine....
    i mean first input the correct answer keys like abcde , and then student no 1 answer keys (abcde) and after enter it will give u random results like some answers are correct and some are incorrect.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories