### How to sum ?

Hi guys . I'm new here and I'm kinda new to programing . I'm trying to complete the task from the book , I done something so far , but I ran into a problem. How to I sum int ? I mean , I know the int+int=? , but this is something different . I need to calculate average girls and boy height. I can't use like u1,u2..,un , it's a pain in the ass . Is there a way to do this ? Can someone help me with this ? ps.sorry for my english (its not my native language).

 12345678910111213141516171819202122 #include #include using namespace std; int main() { int i,n,u,v,m; v=0;m=0; // v = boy : m = girl cout<<"student number :";cin>>n; for(i=0;i<=n;i++) { cout<>u; if(m>=u) { } } return 0; }
declare:
double average = 0;
int sum = 0;

In your for loop (although I have no idea what your m>=u check is all about), you need to do something like this:

sum += u;

then after your for loop you can work out your average by dividing the sum by n.
Something like that.
Break it down into baby steps. Tell the user what input you want, get each input, store each input separately, then calculate the result. You need someplace to store the data for each student (ideally an array but I don't know if you know about them yet).
Last edited on
 You need someplace to store the data for each student (ideally an array but I don't know if you know about them yet).

No, you don't.

You need to know the number of male students, the number of female students, the total height of all male students and the total height of all female students. There is no reason to store individual measurements.
indeed. see my post.
Topic archived. No new replies allowed.