Solved

# Need help with a while loop using cin.peek()

Posted on 2004-03-29

I need help finding some logic errors. My program is getting stuck in the two while loops. This program takes two numbers and then formats the output to scientific notation. Here is the first part of my code. Any help would be greatly appreciated!

int main()

{

double x, y;

x = readNum();

y = readNum();

//printFormatted( x, y );

return 0;

}

double readNum()

{

double num = 0;

double place = 10;

char numb[20];

cout << "Enter a number: ";

cin.get(numb, 20);

while (cin.peek() != '.' || cin.peek() != '\n')

num *= static_cast<double>(cin.get() ) + 10;

while (cin.peek() != '\n') {

num += static_cast< double >( cin.get() ) / place;

place *= 10;

}

cin.ignore();

return num;

}