/*
 #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?

Recommended Answers

All 5 Replies

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.