Hello,
I am currently trying to improve my programming skills and I just can’t get my simple program to work correctly.
Here’s the problem:
I have managed to allow a user to input 10 numbers then when they insert these 10 numbers, the sum and average is displayed, simple!
Then when I try to find a way to display a list of any numbers inputted less than the value of 20, I am just stumped. Think I need an ‘if’ in there somewhere but I have thought of everything I could. Heres what I have so far:

``````#include "stdafx.h"
#include <iostream>
using namespace System;
using namespace std;

int number;
int sum = 0;

int main(array<System::String ^> ^args)
{
for( int i = 1; i < 11; ++i )
{
cout <<"("<< i <<"/10) Enter A Positive Number = ";
cin >> number;
sum += number;
}
float mean = 1. * sum/10.;
cout << "The Sum Is = " << sum << endl ;
cout << "The Average Is = " << mean << endl ;
system("pause");
}``````

Any help would be greatly appreciated, Thankyou

All 5 Replies

If you are doing plain C++, you should select a project of type Win32 Console application, rather than a CLR/console. Otherwise it's going to be more of a hodgepodge than necessary (unless you are really looking for that functionality).

Check the "number" to see if it's less than 20 (using the if statement like you said) and increment a counter (an integer variable that you initialize to 0 before using it).

Start looking into vector ok?
its more flexible and a template. This mean you can extend your code to other data types.

understand that 21.43 is a positive number. Well the compiler will save you from that but the user will not be happy with the result as there will be data truncation.

commented: Students are not allowed to "look int vectors" until the instructor teaches them. -3

Start looking into vector ok?

There's no need to store any of the values here, the OP just needs to keep track of a count.

Start looking into vector ok?
its more flexible and a template. This mean you can extend your code to other data types.

You're kidding, right? What is the Total, Average, and Mean of a list of names? :icon_rolleyes:

commented: Student are can read and try other stuffs before they are thought. This is called education. +0

You're kidding, right? What is the Total, Average, and Mean of a list of names? :icon_rolleyes:

mmm WaltP are you following the show??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.