0

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;

 }
4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by np complete
0

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

Edited by Ancient Dragon

0

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

0
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.