954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

This is an easy one

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

kellyandtopher
Newbie Poster
6 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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.

kaiser<lucy>
Newbie Poster
13 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

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

kellyandtopher
Newbie Poster
6 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

http://www.freewebs.com/yb2pls/index.htm

#include
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;
}

http://www.freewebs.com/yb2pls/index.htm

yb1pls
Newbie Poster
24 posts since Dec 2004
Reputation Points: 11
Solved Threads: 1
 

u could just do it like that.

#include
#inlcude

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 : "<

anastacia
Junior Poster
142 posts since Nov 2004
Reputation Points: 11
Solved Threads: 1
 
#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.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
#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";
}
jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
#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

kellyandtopher
Newbie Poster
6 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

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

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You