Write a program in C++ to prepare a frequency distribution table of the percentage marks in Computer studies of N students, to be taken as inputs, into the following categories
Category Marks(%)
Fail 0-34
Pass 35-59
Good 60-79
Very Good 80-89
Excellent 90 and above
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
why wont this compile correctly as per the question .plz help me.
#include<iostream.h>
#include<conio.h>
void main()
{
int marks[50], n;
cout<<"Enter number of students";
cin>>n;
int fail=0, pass=0, good=0, very good=0, excellent=0;
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
else if ((marks[i]>=36) && (marks[i]<=59))
pass++;
else if ((marks[i]>=60) && (marks[i]<=79))
verygood++;
else if ((marks[i]>=80) && (marks[i]<=89))
excellent++;
else
(marks[i]>=90)
}
getch();
}
First of all, there is a format button that looks like "<>" that provides code tags. It will make it easier for us to review and comment on your post. Please edit you post, highlight the code, and click the button.
Second, C++ standards state that main() must return an int. Your teacher (or tutorial) is giving you bad habits by suggesting void main(). I would strongly suggest you change line 3 appropriately.
Third, if the code won't compile you probably received error messages. Please post what errors you got so we don't have to guess. My ESP is a little bit out of whack today.
#include<iostream> //<--
//#include<conio.h> //<-- what's this?
int main() //<-- int not void
{
int marks[50] = {0}; //<-- initialize
int n = 0; //<-- separate lines
int fail=0, pass=0, good=0, very good=0, excellent=0;// put variables at top
// very good is not a valid variable name
cout<<"Enter number of students";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
elseif ((marks[i]>=36) && (marks[i]<=59))
pass++;
elseif ((marks[i]>=60) && (marks[i]<=79))
verygood++;
elseif ((marks[i]>=80) && (marks[i]<=89))
excellent++;
else
(marks[i]>=90) //<-- what are round brackets for?
}
getch();//<-- what's this for?
return 0; //<-- good practice
}
/*
USE WHITESPACE, INDENTATION AND BLANK LINES
TO MAKE THE CODE READABLE
IF CASCADE IS TOO COMPLICATED
YOU MUST USE std::cout ETC OR using namespace std;
*/
It doesn't display the results because you don't print the results anywhere. You collect the number of fails, passes, etc., but then you don't do anything with them. You need to print them out.
could pls explain me how
The output should display the categories and the corresponding frequencies, i.e, the number of students in each category in two columns.