program in which we calculate total marks in a course and print a course grade by using if-else conditions. However check, if user enters correct marks or not, for example midterm marks is between 0 to 20. If user enters midterm marks less than 0 or greater than 20 then print incorrect marks, please re-enter midterm marks. The same check will be tested with quiz, assignment, lab work and final marks. Then print total marks in a course that is greater than or equal to 0 and less than or equal to 100. Marks distribution as:
Midterm 0-20
Quiz 0-5
Assignment 0-5
Lab Work 0-20
Final 0-50
90 or greater = Grade A
80-89.99 = Grade B
70-79.99 = Grade C
60-69.99 = Grade D
59.99 or lower = Grade F
Here is more detail output screen:
Display: Enter midterm marks:
Input: 15
Display: Enter quiz marks:
Input: 10
Display: You have entered incorrect marks of quiz, please re-enter quiz marks:
Input: 5
Display: Enter assignment marks:
Input: 6
Display: You have entered incorrect marks of assignment, please re-enter assignment marks:
Input: 10
Display: You have entered incorrect marks of assignment, please re-enter assignment marks:
Input: 50
Display: You have entered incorrect marks of assignment, please re-enter assignment marks:
Input: 3
Display: Enter lab marks:
.
.
.
Hint: Quite many if else conditions will be used. Use while or do-while loops to take re-input.

NathanOliver commented: Help and do are two different things. -2

Recommended Answers

All 15 Replies

Looks like a homework assignment.
It is expected of members to at least try to code something themselves
before asking for help.

You do that, and you will find a lot of very knowledgable and helpful members
willing to help you.

hey, i tried a lot, i made it all, but i actually cannot put the while test condition, that takes input and if its wrong it reasks the same question, please do guide me that, please help me with that, yes it is a home assignment, and i have to submit it by saturday, please help

hey, i tried a lot, i made it all

I see no code to show us what you tried so therefore cannot help you fix it.
Unless, of course, you want us to write it for you...

#include<stdio.h>
#include<conio.h>
void main(void)
{
float a=0,mid=0;
while(a<=mid)
{
printf("enter mid marks");
scanf("%f",mid);
if(mid<=20)
{
printf("yes");
}
else
{
printf("No");
}
continue;
}
}

i just tried to make for mid term marks, that if i input mid term marks less than 20, it answers yes and if i answer greater than 20, then it again asks enter mid marks, how to do that?

To simply have it continue to loop only if the entry is below 20
you should use the keyword break; after printf("yes");

Cut you continue; statement out and replace printf("No"); with it.

Better yet, have the while loop test if a good value was entered. Then you wouldn't need the if at all.

Also format your code. If you want help, the people you are asking need to be able to read and follow your code. Formatting is necessary.

i formatted the code, hey break is also not working, actually the most confusing thing is what to put test condition of while or do while to take re input if we input midterm marks greater than 20

please help me

First things first. This is C++ forum not C.

Now your question.

You can make a function that authenticates user input. Make it such that it checks for all types of inputs, like midterm marks, lab marks, quiz marks etc.

int flag = 0 ;

while(true)
{
   cout << " Enter midterm marks : " ;
   cin >> midtermMarks ;

   flag = authenticate( midtermMarks ) ;

   if( flag == 1)

     break ;

    else
    {
       cout << "\n Wrong Input " ;
    }

}

This should work fine. Try implementing it.

After authencation and all, you can calculate total marks and use if else condition to print marks and corresponding grades. Example

if ( totalMarks >= 90 )
{
    cout<<"\n Marks : "<< totalMarks ;
    cout<<"\n Grade : A" ; 
}

else if ( ...

Try it, and post your code.

First things first. This is C++ forum not C.

So? Isn't C++ based on C? Therefore C code is valid.

Now your question.

You can make a function that authenticates user input. Make it such that it checks for all types of inputs, like midterm marks, lab marks, quiz marks etc.

True, but overkill for his current purposes -- learning to simply make a loop.

This should work fine. Try implementing it.

Terrible! Why use an endless while loop and break out of it when while (flag) is designed to do it without the break?

hey this works, but it isnt working like if i input less than 0 and greater than 20, it generates, retype mid term marks, and if i input betweeen 0-20 it proceeds

You should alter the code you have been given.
as you do so, you will learn something and sleep
better knowing you have actually earned at least
some of the credits you may get from it.

hey this works, but it isnt working...

What? How can it work but not work?

like if i input less than 0 and greater than 20,

OK, you're testing your limits as the instructions say you need...

it generates, retype mid term marks,

Generates? You mean it outputs? Or something else? If you mean outputs, that's what your instructions said you need.

and if i input betweeen 0-20 it proceeds

And that's what the instructions say it should do, isn't it? So there's not a problem, right?

I guess I don't understand your post...

Ok, as WaltP sir pointed out, I did a bad mistake, which results in really bad logic.

authenticate ( char * ) returns 1 if marks is valid, else 0.

This is what WaltP wants ( I hope )

 int flag = 0 ;

   while(flag == 0)
   {

       cout << " Enter midterm marks : " ;
       cin >> midtermMarks ;

       flag = authenticate( midtermMarks ) ;

       if( flag == 0)

          cout << " Wrong Input ";

   }

but overkill for his current purposes -- learning to simply make a loop

But I thought making functions for each task, makes the program more clean.
I may be wrong, would you please elaborate ?

Much better.... ;o)

What I meant was "make a function that authenticates user input. Make it such that it checks for all types of inputs, like midterm marks, lab marks, quiz marks etc. is overkill-- at least if each are graded differently. Since the loop seems to be the learning feature, functions will help see the loop structure better by taking the clutter out of the loop. Cleaner as you say.

But it might also detract by adding another layer of learning over and above the preceived lesson if functions have not been introduced. Since we don't know what the OP has learned yet, we don't know if functions are available. I'm not saying it's a bad suggestion, though...

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.