Hi this is my first post, I am having a problem with loops. I am reading through South-Western's Introduction to C++ 3rd ed. In chapeter 6, activity 6-2 it tells you to make a program that asks or a series of integers one at a time except for 0. When you enter 0 the program takes the numbers you put in and finds the average, the largest number you put in, the smallest number you put in, and the range of the numbers you put in. I got it to do all of the following, but for some reason it wont print to the screen. I think I just have my statements in the wrong order or something, I'm using Dev-C++ and here is my source:
Code:
#include <iostream>
using namespace std;
int main()
{
int i, lar, sma, non;
float av;
av=0.0;
non=0;
sma=2147483647;
lar=-2147483648;
do
{
cin >> i;
cout << "You Entered " << i << endl;
av=av+i;
non+=1;
if(i>lar)
{lar=i;}k
if(i<sma)
{sma=i;}
if(i=0)
{cout << "Average = " << av/non << endl;
cout << "Largest = " << lar << endl;
cout << "Smallest = " << sma << endl;
cout << "Range = " << lar-sma << endl;
break;}
}
while(1);
return 0;
}
Can anyone help me out? I've been messing around with it for an hour and decided to ask for help.