Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i wrote this but it doesnt work

What I have tried:

C++
#include <iostream.h>
#include <conio.h>

struct s
{
    char name[10];
    int d1,d2,d3;
    int vd1,vd2,vd3;
    float avg;
};
int main()
{

    s p[10];
    s d[2];
    int i,j,l=0,P=0,K=0,mx=0,mn=0;
    for(i=0;i<4;i++)
        {
            cout<<"Enter a Name";
            cin>>p[i].name;
            cout<<"Enter  Nomreh Dars 1 And Vahed Dars1";
            cin>>p[i].d1>>p[i].vd1;
            cout<<"Enter  Nomreh Dars 2 And Vahed Dars2";
            cin>>p[i].d2>>p[i].vd2;
            cout<<"Enter  Nomreh Dars 3 And Vahed Dars3";
            cin>>p[i].d3>>p[i].vd3;
            l=(p[i].vd1)+(p[i].vd2)+(p[i].vd3);
             p[i].avg=((p[i].d1*p[i].vd1)+(p[i].d2*p[i].vd2)+(p[i].d3*p[i].vd3))/l;

        }



       for(i=0;i<4;++i)
            for(j=i+1;j<4;++j)
         {
          if(p[i].avg>mx)
            K=i;
            mx=p[i].avg;
         }
          for(i=0;i<4;++i)
            for(j=i+1;j<4;++j)
         {
          if(p[i].avg
Posted
Updated 13-Feb-22 10:02am
v2

Follow the link to get and display the student information:
C++ Program to Store and Display Information Using Structure[^]

Further you can check the following guide to Learn C++
Learn C++ – Skill up with our free tutorials[^]
 
Share this answer
 
v2
Start by not using single character variable names: always use names that reflect what the variable / method / struct is used for - single character names make your code hard to read, and also make it very easy to make mistakes.

Then, stop diving into code immediately, and spend some time thinking about the project and what it requires you to do.

This may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Quote:
i wrote this but it doesnt work

Difficult to tell what is wrong since you didn't told how the program fail, or error messages, and code is not complete.
The most obvious, requirement says 20 student, you allocate array for 10 and your code runs for 4 students.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900