Help: Program For My Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Apolakkiatis
    New Member
    • Jan 2008
    • 30

    Help: Program For My Class

    SOMEONE PLEASE HELP ME.... I HAVE TO REMOVE THE LEADING WHITESPACE IN THIS PROGRAM FOR MY CSE CLASS!!!

    IT'S DUE IN A FEW HOURS

    PRETTY MUCH IT'S A PROGRAM TO CHANGE NUMBERS FROM ACCOUNTING STYLE TO COMPUTER NUMBERS

    FOR EXAMPLE: ($3,432.54) BECOMES -3432.54

    IN THE INSTRUCTIONS WE HAVE TO GET RID OF THE LEADING WHITESPACE AND I CAN'T DO IT....


    Code:
    #include <iostream>
    #include <cmath>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    	char InputC;
    	ifstream IValues;
    	ofstream OValues;
    
    	IValues.open("Input Values.txt");
    
    	if(IValues.fail())
    	{cout << "ERROR: Your accounting file did not open.";
    	return 1;}
    
    	OValues.open("Output File.txt");
    
    	while (!IValues.eof())
    	{
    	IValues.get(InputC);
    	switch(InputC)
    	{
    	case ' ' : {if (IValues.peek() == ' ' || IValues.peek() == '\t' )
    				   break;
    			   else OValues << " ";} 
    	case '\t': {if (IValues.peek() == '\t' || IValues.peek() == ' ' )
    					break;
    			   else OValues << " ";}
    	case '$' : break;
    	case ',' : break;
    	case '(' : OValues << '-';
    	case ')' : break;
    	case '.' : OValues << ".";
    				break;
    	case '1' : OValues << "1";
    				break;
    	case '2' : OValues << "2";
    				break;
    	case '3' : OValues << "3";
    				break;
    	case '4' : OValues << "4";
    				break;
    	case '5' : OValues << "5";
    				break;
    	case '6' : OValues << "6";
    				break;
    	case '7' : OValues << "7";
    				break;
    	case '8' : OValues << "8";
    				break;
    	case '9' : OValues << "9";
    				break;
    	case '0' : OValues << "0";
    				break;
    	case '\n' : OValues << "\n";
    	default  : break;
    	}}
    
    
    
    	return 0;}
  • Apolakkiatis
    New Member
    • Jan 2008
    • 30

    #2
    P.s. I Also Have To Make The Tabs And Spaces One Space

    Comment

    • Lintwurm
      New Member
      • Sep 2008
      • 7

      #3
      Instead of: IValues.get(Inp utC)

      Just do a normal in... for instance cin<<variable.. .
      instead of variable.get(ci n)

      The .get function just means that whatever is in front of the word, it will get used as well...
      doing a normal cin (as example)... This will ignore whitespace...

      As far as I know


      Hope this help =)

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Apolakkiatis-

        Please review the Posting Guidelines of this site, specifically the ones that request you: not using all caps, not capitalizing the first letter of every word, using proper English, and using good thread titles.

        Now that you 1) are a contributing member (with 30 posts so far) and 2) have been officially asked to review the Guidelines, you will be expected to know and abide by all of them - not just the ones I have referenced.

        Thanks,

        sicarie

        Comment

        Working...