#include <iostream>
#include <string>
using namespace std;
int main()
{
double numbers = 0,total = 0,totalCounter = 0,less = 0,more = 0,tester = 0;
char breaker = static_cast<char>(numbers);
cout << "Enter a list of numbers to get the average, max, min, sum, and standard deviation" << endl;
while(tester = 0)
{
cout << "Enter a number or s to quit: ";
cin >> numbers;
if(breaker != 's')
{
totalCounter++;
total += numbers;
if(numbers >= more)
more = numbers;
if(numbers <= less)
less = numbers;
}
if(breaker = 's')
tester = 1;
}
cout << "Total numbers inputted: ";
cout << totalCounter << endl;
cout << "The average equals: ";
cout << total/totalCounter << endl;
cout << "The sum equals: ";
cout << total << endl;
cout << "The max is: ";
cout << more << endl;
cout << "The min is: ";
cout << less << endl;
return 0;
}
I was wondering if there was anything wrong with the way my loop is formatted? My original intention was for the user to input 's' for stop but I don't understand how to convert a double into a char.
Thanks for any feedback!
Noxxid
Calculation prog
Hi all,
I've recently started programming in C++ and am trying to create a program that does the following: calculates the amount of numbers a user enters, the average, sum, min, max and standard deviation. My code looks something like this so far.
Quote:Original post by NoxxidYou can't convert a double into a char, at least not how you want to. You'd have to read in a string first and then convert it the other way.
I was wondering if there was anything wrong with the way my loop is formatted? My original intention was for the user to input 's' for stop but I don't understand how to convert a double into a char.
However you can just ctrl-c to exit anyway, so why bother?
iMalc's right. Read in a string. Check if that string is 's'. Then convert the string to a double. (This bit may require using an atof function, or something. Someone else knows better than I do.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement