whats wrong?!?

This is a discussion on whats wrong?!? within the C++ Programming forums, part of the General Programming Boards category; Hi im trying to make a program that translates $'s into 's. I tryed typing this but there was a ...

  1. #1
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31

    whats wrong?!?

    Hi im trying to make a program that translates $'s into 's. I tryed typing this but there was a error. PLease can u correct it?
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
          float dollar, pounds;
          cout << "Type in how many dollars you want to translate:  ";
          cin >> dollar;
          
          if( (pounds = 1 )
          cout << "60 pence" << endl;
          else if ( pounds = 2) 
          cout << "1 pound twenty pence" << endl;
          else if ( pounds = 3)
          cout << "1 pound eighty pence" << endl;
          
          // The pounds and dollars go om for ages until it goes up to $50
          
          char c;
          cin >> c;
        
           return 0;
    }

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    use == not = to compare values. = assigns values, == compares in C++
    Woop?

  3. #3
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31
    It says that "cout << "60 pence" << endl; " was wrong though! I did put the == in btw

  4. #4
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    [my two cents]
    Also, that's not the most useful program, really. What if I have $1.78?

    You should use a formula to convert from dollars to pounds instead.
    [/my one pence]

    forgive me.

    EDIT:
    It says that "cout << "60 pence" << endl; " was wrong though!
    What was the error message?
    Last edited by Decrypt; 04-23-2006 at 11:46 AM.
    There is a difference between tedious and difficult.

  5. #5
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31
    It was "expected `)' before "cout"

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,203
    if( (pounds = 1 )

    You have too many ( in this line.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Code:
    float dollar, pounds;
    cout << "Type in how many dollars you want to translate:  ";
    cin >> dollar;
          
    if( pounds == 1 )
    
    ...
    You are reading in a value from the user into the dollar variable and then everything else after that is looking at the pounds variable which is uninitialized at this point. Seems you want to be using dollar instead of pounds in all of those if statements.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31
    Yaay!!! It works now!
    ty Shakti!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21