I need to write a program that finds the sum and average of 50 numbers.

I am very new to C++, I have learned VB and this is really confusing to me. Please help me with this simple program. I went to another forum and had no responses.

Kelly

eh the easiest solution would just be something like

int average()
{
     int number, total = 0, avg;
     for(int x = 1; x <= 50; x++ )
     {
           cout << "enter your " << x << "th number :";
           cin >> number;

           total += number;
     }

     avg = total / 50;
     return avg;
}

err...edit: you may want to make it so that it takes care of 1,2,3 otherwise you'll get 1th 2th 3th.

Thank you I just want to let anyone know that I actually didnt need this for school. I did want to know how this forum worked cause the last one just didnt respond. So I thank you for your input. Thank you Lucy I will save that and work on it to help with other programs.

Kelly

#include <iostream.h>
void main()

{
     int number, sum, total = 0, avg;
     for(int n = 1; n <= 50; n++ )
     {
           cout << "enter number " << n << endl;
           cin >> number;

           total += number;
     }

     sum = total;
     avg = total / 50;
     cout << "total " << sum << endl;
     cout << "average " << avg << endl;
}

u could just do it like that.

#include<iostream.h>
#inlcude<conio.h>

void main()
{

int number,sum=0,average;
clrscr();

// entering the data

for ( int i=0; i<50; i++)
{

cout<<" Please enter a number: ";
cin>>number;

sum=sum+number;
}

average=sum/50;

// displaying the results
cout<<" the sum is : "<<sum<<endl;

cout<<" the average is : "<<average<<endl;


getch();
}


that should approximately work. if u get some errors, i am sure u are able enough to correct them

#include<iostream.h>

// This is a nonstandard header. Please stop using it and instead use <iostream>.
#inlcude<conio.h>    // This is a nonstandard header. Please stop using it for sample code. (And try compiling to catch the typo.)
void main()          // This is not correct, it should be int main()
clrscr();            // This is unnecessary and nonstandard.  Please stop using it for sample code.
getch();             // This is unnecessary and nonstandard.  Please stop using it for sample code.

Nice additions. :rolleyes: And please use [code][/code] tags.

#include <iostream>
using namespace std;
void main(void){
cout<<"1 2 lazy 2 do my own homework therefore 1 got this solutiun frum sum website";
}
#include <iostream>
using namespace std;
void main(void){
cout<<"1 2 lazy 2 do my own homework therefore 1 got this solutiun frum sum website";
}

This is a reply to this quote. If you read what I wrote a few replies ago you would have seen that I didn't need this for homework. But, thanks for the input.

Kelly

Hello,

I am locking this thread before it gets out of hand.

There is no way anyone here can know if it is for homework, or for pleasure, or for work/job reasons. With the amount of students out there, the assumption is made that it is homework related.

What we do know is that no matter how the bytes fall, they are intellectual property. It is DaniWeb policy to be a source of information, but not to do the whole project for the requestor. It is a touchy balance that has to be respected.

When we ask for "show work", that implies that you made an effort to understand the problem. This means code out some stuff... it doesn't necessairly have to work, just put your ideas down as to how the program should flow. Coming from a VB background, you shold have some idea of program flow and control. Perhaps write it in VB, and then ask how to convert it to C++. Porting is a skill in itself.

Community members should also not make assumptions on what the poster is asking. If you as a member feel that the poster is "getting away with something" then don't post... let the thread sit empty. A silent non-action speaks profoundly.

Christian

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.