Newbie C++ programmer again...

Robert Ambrose rna@testpt.com
Fri, 18 Aug 2000 09:33:02 -0700 (MST)


The short answer is the state in the ios parent class has to be reset to
good (cleared).  The long answer reauires to much typing ;-), and I've
spent to much time on this already (anthough I did learn some usefull
things).  If you really want to know, I'm always happy to talk it over a
beer.

Here's a working program:

#include <iostream.h>
#include <ctype.h>
#include <limits.h>
 
int main ()
{
	for(;;)
	{
		double dollars;	// Maybe I'll win the lotto

		cout << "Enter dollars:";

		if(cin >> dollars)
		{
			double pounds;

			pounds = dollars / 1.49;
			cout << "is " << pounds << " pounds" << endl;
			break;
		}
		else
		{
			cin.clear();
			cin.ignore(INT_MAX, '\n');
			cout << "Not a valid dollar ammount, try again" << endl;
		}
	}

	return 0;
}

rna

On Fri, 18 Aug 2000, Eric Samson wrote:

> Ok, I have about gone nuts trying to figure this out...
> 
> This is my assignment that I am having trouble with..
> 
> It's a simple currency converter, the user enters a float which indicates 
> how many US dollars they want to convert to a specified currency, in my case 
> Deutchmarks...  That is the easy part, got it written no problem, simple 
> math... An optional part of the assignment is to validate the user input and 
> be sure it is a numeric value (float), and not an alpha charater, symbol, 
> etc...  If they enter something that will not work, they are supposed to be 
> prompted to try to enter the info again...  Preventing negative values is no 
> problem with the <while (someinput < 0)> loop, but if they enter an alpha 
> value, it enters an infinite loop.  I went to borders last night and my 
> roommate and I (mostly because he is tired of hearing me whine about it) 
> looked in a bunch of books for a solution, and didn't have any luck.  My 
> instructor was no help either, he wasn't sure how to do it (he is a VB 
> programmer teaching C++, go figure)...  This seems like something that 
> should be painfully simple...  Is this something too complex for a beginning 
> programmer?  I should think that it would be a basic part of programming, 
> but I could be wrong...  I notice a few people on here saying they don't use 
> C++ much, so what is the language of choice for programming in Linux?
> 
> Thanks again,
> 
> Eric
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> 
> 
> _______________________________________________
> Plug-devel mailing list  -  Plug-devel@lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel
>