Thread: Can't get output to display dollar sign

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Can't get output to display dollar sign

    I am still working on my mail order program. I have got the program to the point where it needs to output the amounts with a dollar sign. When I code '$' in I can not figure out where to put it so that I do not get an error with it. Here is the code that I am trying to output:

    Code:
    // ouput summary of results
    	cout << "\n\nTotals for each product sold are: "
    	       << "\nProduct 1: " << ( aCount * 2.98 )   // display dollar amount of product1		   
    	       << "\nProduct 2: " << ( bCount * 4.50 )   // display dollar amount of product2		   
    	       << "\nProduct 3: " << ( cCount * 9.98 )   // display dollar amount of product3		   
    	       << "\nProduct 4: " << ( dCount * 4.49 )   // display dollar amount of product4		   
    	       << "\nProduct 5: " << ( eCount * 6.87 )   // display dollar amount of product5
    		   << "\nQuantity of all products sold: " << ( quantitySold = aCount + bCount + cCount + dCount + eCount )
    		   << endl;
    Also is it possible to output this, for example, product 1: 6 @ $2.98 = $17.88? If so would it be coded here in my output summary or up in the program?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can chain the operator<< calls (technically you are already chaining them). Just write out everything you want to display like in your example. Then replace the variable values (like 6 and 17.88) with the code that produces them. Then put double quotes areound the rest of the text snippets before, after and between each variable value. Finally, add << between each piece, the quoted strings and the variable values.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    14
    I changed the code to this:
    Code:
    << "\nProduct 1: " << " aCount " << "@ " << " $" << "2.98 " << " =" << " $" << ( aCount * 2.98 )
    It ouputs everything right except for the aCount. It prints out aCount instead of the number of items. Am I not understanding where the count is coming from? If need be I can post my programming so that you can see what I have so far.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Variables aren't placed under quotes.

    Code:
    cout << "\nProduct 1: " << aCount << "@ " << " $" << "2.98 " << " =" << " $" << ( aCount * 2.98 )
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    14
    Thank you. I got it figured out. I had to place ( quantitySold = aCount ) where I had just aCount.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I got it figured out. I had to place ( quantitySold = aCount ) where I had just aCount.

    No you didn't, you just had to remove the quotes around aCount. You should probably do the assignment to quantitySold later like your original code does.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  2. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  3. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  4. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM