I am trying to output an arbitary double number (which might be negative) using only the printDigit for I/O, but when I run this program and you enter in a number is doesn't output anything.

#include <iostream>
using namespace std;

void printDigit( int n )
{   

cout<< n;
}

double printOut(int n)
{

if ( n < 0 )
{
    cout << "-";
}
n = -n;

if ( n >= 10 )
{
    printOut( n / 10 );
    printDigit( n % 10);

}

}

int main()
{
    double n;
    cout << "Please enter a number: ";
    cin >> n;

    printOut(n);


    cout <<endl;
    cout <<endl;

    system("pause");
    return 0;

 }

line 17 should be moved up so that its within the bracketed if statement that starts on line 13.

Now it only outputs the second digit in a number like if you entered 45.37 it would output 5

In printOut(), is the value of n accurate? Better check...

Would I have to cast n to be a double?

int main()
{
    double n;
    cout << "Please enter a number: ";
    cin >> n;

    printOut(n);

Isn't it already a double?

-----------------

double printOut(int n)
{

// what's the value of N right here?
if ( n < 0 )

See the comment

printOut(..) has argument which is of type integer. Where as you are passing a double number.

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.