473,414 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

simple program help

Problem 1 - Min, Mean, Max

Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the program has read in the values, the program will output the minimum value entered, the maximum value entered, and the mean (average) of the values entered (to two decimal places). If the user does not enter any numbers before entering 0, the program will display the message "No numbers were read".


Sample outputs:
Please enter some integers, and a 0 (zero) to terminate:
1 2 3 4 5 0
The minimum number entered was 1
The maximum number entered was 5
The mean of the numbers was 3.00
Press any key to continue . . .




Please enter some integers, and a 0 (zero) to terminate:
1 2 3 4 5 6 7 8 9 10 0
The minimum number entered was 1
The maximum number entered was 10
The mean of the numbers was 5.50
Press any key to continue . . .




Please enter some integers, and a 0 (zero) to terminate:
0
No numbers were read.
Press any key to continue . . .


You may assume that the user enters a valid integer.




this is what i have so far although i dont really have a clue what im doing help most appreciated:)


#include <iostream>
#include <cmath>
using namespace std;

int main ()

{
cout << "Please enter some integers, and a 0 (zero) to terminate:" <<endl;

int num;

do
{
int num;
cin >> num;

if (num =0)
{
cout << "No numbers were read." << endl;

}

else;
}

while (num !=0)
{
int minimum;
int count = 0;

count++; //Add one to count
}

cout << count << endl;

return 0;
}
Oct 14 '06 #1
4 3090
okay ive done it up a little better now. hopefully this helps a bit

#include <iostream>
#include <iomanip>
using namespace std;


int main ()

{

cout << "Please enter some integers, and a 0 (zero) to terminate:" <<endl;
cout << endl;

int number;
cin >> number;

if (number == 0)
{
cout << endl;
cout << "No numbers were read." << endl;
cout << endl;
}

int min = 0;
int max = 0;
int mean = 0;
int count = 0;

while (number != 0);
{

int number;
count ++;
cin >> number;

if (number == 0)
{
cout << count << endl;
cout << endl;
cout << "The minimum number entered was " << min << endl;
cout << endl;
cout << "The maximum number entered was " << endl;
cout << endl;
cout << "The mean of the numbers was " << mean / count << endl;
cout << endl;
}
}
return 0;
}


i am however stil not getting it to work if someone enters a zero after, and the min, max, and mean are hard to do to
Oct 15 '06 #2
Banfa
9,065 Expert Mod 8TB
Don't declare

int number;

twice

intialise min to INT_MAX and max to INT_MIN defined in limits.h then

Expand|Select|Wrap|Line Numbers
  1. if (number < min)
  2.    min = number;
  3.  
gets the minimum and something similar for the maximum.

To calculate the mean you will need to total all the numbers entered.

count should only be incremented if number is non-zero

put your calculations before getting a new number in the loop.
Oct 16 '06 #3
okay i changed it to a for statement now and got the count to work and only have one cin >>

now btw we cant use min, max functions. we have to create our own using if statements and stuff. sorry im really new to this.

#include <iostream>
#include <iomanip>
using namespace std;


int main ()

{

int number = 0;
int count = 0;
int min = 0;
int mean = 0;
int somenum = 0;
int x;

cout << "Please enter some integers, and a 0 (zero) to terminate:" <<endl;
cout << endl;

for (mean = 0; somenum = 1; somenum++)
{

cin >> number;

if (number == 0)
{
cout << count - 1 << endl;
cout << endl;
cout << "The minimum number entered was " << min << endl;
cout << endl;
cout << "The maximum number entered was " << somenum - 1 << endl;
cout << endl;
cout << "The mean of the numbers was " << mean / (count - 1) << endl;
cout << endl;
}

}

return 0;
}
Oct 16 '06 #4
Banfa
9,065 Expert Mod 8TB
now btw we cant use min, max functions. we have to create our own using if statements and stuff. sorry im really new to this.
If you read what I posted you will find I haven't used min() or max().

You previous code had less errors than you latest code.

Start with tring to input a set of numbers until 0 is input and printing out the value of the smallest number entered (i.e. forget about the mean and the max to start with and use the code snipit I posted).
Oct 16 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
3
by: Bore Biko | last post by:
Dear, I don't have enought money to by a original Visual C++, so I use Visual C++ 6.0 Enterprise edition, this version doesen't have a HELP. Most of my friends programmers praise C++, as a...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
4
by: Break2 | last post by:
I am trying to write a simple program which asks a user to enter 5 integers after which the average will be computed and written to the screen. That simple. However I want to do it according to a...
2
by: jerger | last post by:
I have converted my dictionary program into a simple asp program. It works great... but I now want to add speech functionality but have not had any success. I have tried several online templates that...
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.