This program is supposed to take in four scores two are assignment scores and the other two are test scores it should only take in score that are 0 to 100 me test chain goes someting like this

//check for valid data
	if (test1<0 ||test1>100)&& (test2<0||test2>100)&& (assign1<0||assign1>100)&&(assign2<0||assign2>100)
	{
		printf("Error your score must be between 0 and 100\n");
		printf("Please Enter two test scores\n");
        scanf("%f,%f", &test1,&test2);
		printf("Please Enter two assignment scores\n");
        scanf("%f,%f", &assign1,&assign2);

	}

I know its probably wrong but could I have no idea why i'm thinking the chain is too long any other ideas?

Recommended Answers

All 10 Replies

offhand I'd say it looks fine, though you may consider inputting each one and checking it separately. That way if the 2nd assignment is wrong, you don't have to input the other 3 again.

Why not just write a small check function which will do the small grained tasks for you which unnecessarily clutter the "main()".

int is_valid( int value )
{
    if ( value < 0 || value > 100 )
        return 0 ;
    else
        return 1 ;
}

And carrying ahead with Mr. Infarcion's advice, do something like

// ask the user to enter the data in a loop
// accept the data in the required variable
if( is_valid( required_variable ) )
    continue;
else
{
    printf ("Data out of range") ;
    exit (1) ;
}

Hope it helped, bye.

I kept get error with it are you sure its correct?

Maybe you can simply modify the code like this:
if (test1<0 ||test1>100)
&& (test2<0||test2>100)
&& (assign1<0||assign1>100)
&&(assign2<0||assign2>100)

nope, is there supposed to be a semicolon somewhwere in that line before the && operator?

What kind of error you gettting ? Post your entire recent code and highlight the line on which you are getting the error.

ok i'm getting a bunch of errors but most of them are missing ";" before "&&" here's the whole thing

int main()
{
//intitialize variables
float test1,test2,assign1,assign2,avg_test,avg_assign;
const float pass_grade=0.50;

//get user input
printf("Please enter two test scores");
scanf_s("%f,%f",&test1,&test2);
printf("Please Enter two assignment scores\n");
scanf_s("%f,%f", &assign1,&assign2);

//check for valid data
	while  (test1<0 ||test1>100)&& (test2<0||test2>100)&& (assign1<0||assign1>100)&&(assign2<0||assign2>100);
	{
		printf("Error your score must be between 0 and 100\n");
		printf("Please Enter two test scores\n");
        scanf_s("%f,%f", &test1,&test2);
		printf("Please Enter two assignment scores\n");
        scanf_s("%f,%f", &assign1,&assign2);

	}
	
	
		avg_test=test1+test2/2;
		avg_assign=assign1+assign2/2;
	
	
		if  (avg_test>=avg_assign)&& (avg_test>=pass_grade);
		{
			printf ("You have passed because of your test grade :%.2f",avg_test);
		
		else if(avg_assign>=avg_test) &&(avg_assign>=pass_grade);
		  {

		   printf ("You have passed because of your assignment grade :%.2f",avg_assign);

		   }
		else if (avg_test>avg_assign);
		{
			printf ("Your test grade was not high enough you have failed %.2f",avg_test);
		}
		else
		{
			printf ("Your assignment grade was not high enough you have failed %.2f",avg_assign);
		}

		

	return 0;

Looks like you have a major problem with your syntax concepts.

1. There should be no semicolon after the conditional stmts
if ( ) ; is wrong

2. You need to nest your braces properly.

if (something) && (something eles) .. is wrong

It should be like

if ( (something) && (something eles) )
int main()
{
//intitialize variables
float test1,test2,assign1,assign2,avg_test,avg_assign;
const float pass_grade=0.50;

//get user input
printf("Please enter two test scores");
scanf_s("%f,%f",&test1,&test2);
printf("Please Enter two assignment scores\n");
scanf_s("%f,%f", &assign1,&assign2);

//check for valid data
    while ( (test1<0 ||test1>100)&& (test2<0||test2>100)&& (assign1<0||assign1>100)&&(assign2<0||assign2>100))
    {
        printf("Error your score must be between 0 and 100\n");
        printf("Please Enter two test scores\n");
        scanf_s("%f,%f", &test1,&test2);
        printf("Please Enter two assignment scores\n");
        scanf_s("%f,%f", &assign1,&assign2);

    }


        avg_test=test1+test2/2;
        avg_assign=assign1+assign2/2;


        if  ((avg_test>=avg_assign)&& (avg_test>=pass_grade))
        {
            printf ("You have passed because of your test grade :%.2f",avg_test);
        }

        else if((avg_assign>=avg_test) &&(avg_assign>=pass_grade))
          {

           printf ("You have passed because of your assignment grade :%.2f",avg_assign);

           }
        else if (avg_test>avg_assign)
        {
            printf ("Your test grade was not high enough you have failed %.2f",avg_test);
        }
        else
        {
            printf ("Your assignment grade was not high enough you have failed %.2f",avg_assign);
        }



    return 0;
        }

wow thks, seems i've got alot to learn, know of any good newbie tutorials?
also the program dosent wait for the assignment scores would it be better to read all of the scores in at one time?

Some good newbie tuts HERE.

Also try adding getchar() before return 0 for the screen to wait for you to see the results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.