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

int main()
{
    
    cout << " " << endl;
    double sum;
    double numb;
    double ave;
    int counter = 0;
    
    cout << "This program averages numbers." << endl;
    cout << endl;
    while (true)
    {
        cout << "Number: ";  
        cin >> numb;
	if( numb < 0 )
		break;
        else 
         {
           sum += numb;
           counter ++;
         }
         
    }
    ave = sum / counter;
    cout << fixed << "The average is " <<  ave << "." << endl;
   
}

My Problem: If I get an average of 5.40000 (example), my checking system (on my professor's pg) want's the output to be 5.4; but here's the kicker, if the average is something similar to 3.4523, it want's that value with removing the other decimals...so I can't use setprecision(x)...I've tried...

Any advice?

Convert it to a string, remove trailing 0's, the output the string.

ok, but I have no idea how...

should I make my output like below?
cout << fixed << "The average is " << (str)ave << "." << endl;

You have to look into how to convert a float into a string first. Check your book.

Believe it or not, my Professor doesn't have a chosen text for the course, all notes...but I'll find it. Thank you for the guidance.

Edited 6 Years Ago by XStrong: n/a

This article has been dead for over six months. Start a new discussion instead.