Hello, I'm trying to figure out why this won't work when I put in a number at the first prompt, and then a 0 at the 2nd or later. It seems to hinge on having double x = 0.0 in there. The thing is, I need to be able to have a user enter values with decimal places.
// project2b.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
usingnamespace std;
#include <iomanip>
int _tmain(int argc, _TCHAR* argv[])
{
{
int x;
int i=0;
int sum=0;
cout << "Please enter a number (0 to quit) --> ";
cin >> x;
while (x != 0)
{
cout << "Enter the next number (0 to quit) -->";
cin >> x;
sum += x;
i++;
double x = 0.0;
}
cout << setprecision(2) << fixed << "Sum = " << sum << endl;
cout << setprecision(2) << fixed << "Average = " << sum / i << endl;
}
return 0;
}