strcmp confusion

Question: Prof. Alban Azizaj is giving lesson to two classes. He has 2 students in one class and three students in the other class. Read the student information and find the class with the highest average.

Input specification
You will be given five lines of information. In every line, you will have class name, student name, student surname, and student grade. Where class name is at most 3 characters containing only English letters or digit from 0 to 9. Name and surname are at most 15 characters containing only English letters. Student grade is an integer between 1 and 100.

Output specification
Show the class name and average (with 2 digits precision) which has the highest average.

Sample Input I ----- Sample Output I
10A Andi Visari 80 -----11A 91
10A Enis Dosari 67
11A Genti Agolli 92
10A Evis Drita 47
11A Erion Shehu 90

----------------------------------------------------
MY CODE:
----------------------------------------------------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
  char classname,name,surname;
  char class1,class11,class111,class1111,class11111,class2,class22,class222,class2222;
  int grade,sum,av1,av2,cnt,cnt3;
  cin>>classname;cin>>name;cin>>surname;cin>>grade;
  classname=class1;sum=grade;cnt=1;
  cin>>classname;cin>>name;cin>>surname;cin>>grade;
  if strcmp(classname,class1)==0; classname=class11;sum1+=grade;cnt3++1; 
  	else classname=class2;sum2+=grade;cnt++1;
  cin>>classname;cin>>name;cin>>surname;cin>>grade;
  if (strcmp(classname,class1)==0) classname=class111;sum1+=grade;cnt3++1; 
  	else classname=class22;sum2+=grade;cnt++1;
  	cin>>classname;cin>>name;cin>>surname;cin>>grade;
  if (strcmp(classname,class1)==0) classname=class1111;sum1+=grade;cnt3++1; 
  	else classname=class222;sum2+=grade;cnt++1;
  	cin>>classname;cin>>name;cin>>surname;cin>>grade;
  if (strcmp(classname,class1)==0) classname=class11111;sum1+=grade;cnt3++1; 
  	else classname=class2222;sum2+=grade;cnt++1;
  	
  	if (sum1>sum2) av1=sum1/cnt3; cout<<class1<<endl;cout<<av1<<endl;
  	else if (sum1<sum2) av2=sum2/cnt;cout<<class2<<endl;cout<<av2<<endl;
  return 0;
  }
Last edited on
What is the question?
Question: Prof. Alban Azizaj is giving lesson to two classes. He has 2 students in one class and three students in the other class. Read the student information and find the class with the highest average.
Topic archived. No new replies allowed.