What went wrong?

Discussion in 'Programming General' started by booyaboy234, Aug 7, 2008.

What went wrong?
  1. Unread #1 - Aug 7, 2008 at 5:53 PM
  2. booyaboy234
    Joined:
    Aug 7, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    booyaboy234 Newcomer

    What went wrong?

    I'm trying to write a program in dev c++ that squares numbers buit i cant find out what is going wrong when i try to compile it. I was hoping someone here could.
    Code:
    //
     //   program to convert integers to there squares
     //
     #include <cstdio> 
     #include <iostream>
     using namespace std;
     
     int main(int nNumberofArgs, char* pszArgs[])
     {
     //enter numbr to be squared
     int number;
     cout << "enter number to be squared:";
     cin >> number;
     
     // use conversion factor to convert numeral
     // into square
     int integer;
     square = number * number;
     
     // output results (followed by a NewLine)
     cout << "squared value is:";
     cout << square << end];
     
     // wait until user is ready to terminater program
     // to allow user to view results
     system("PAUSE");
     return 0;
    }
     
    
     
  3. Unread #2 - Aug 7, 2008 at 6:20 PM
  4. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    What went wrong?

    int integer;
    should be int square
     
  5. Unread #3 - Aug 7, 2008 at 11:57 PM
  6. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    What went wrong?

    Code:
     cout << square << end];
    Shouldn't that be endl?
     
  7. Unread #4 - Aug 8, 2008 at 3:01 AM
  8. booyaboy234
    Joined:
    Aug 7, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    booyaboy234 Newcomer

    What went wrong?

    I actually didn't need that line at all.
    and thanks alot SMR
     
  9. Unread #5 - Aug 8, 2008 at 3:25 AM
  10. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    What went wrong?

    You do need that line if you intend on displaying the squared number.

    Isn't there an operator for powers anyway? '^' (or is that bitwise XOR?)
     
  11. Unread #6 - Aug 8, 2008 at 9:33 AM
  12. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    What went wrong?

    C++ doesn't use ^ for exponents. But there's pow() in math.h.
     
  13. Unread #7 - Aug 8, 2008 at 1:04 PM
  14. booyaboy234
    Joined:
    Aug 7, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    booyaboy234 Newcomer

    What went wrong?

    sorry, i meant the "end]" part
     
  15. Unread #8 - Aug 8, 2008 at 8:12 PM
  16. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    What went wrong?

    What you could actually do is rather than

    Code:
    << endl;
    For newlines, you can use escape characters if you still have an "open string", e.g.

    Code:
     cout << "example string\n"; 
    And so on.

    It would be good if you also checked out the printf and s_printf functions inside stdio (I think that's the header file, but they may be included in Iostream too, not sure).

    SMR:

    Thanks for clearing that up. I've been using C# way too much recently (either that or I'm completely mucked up in the head when it comes to operators, either or)
     
  17. Unread #9 - Aug 14, 2008 at 3:08 AM
  18. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    What went wrong?

    NP. Also, printf_s*
     
< Help with a private server on silkroad online | Whats the code so that when someone types the info on the visual it sends to u email >

Users viewing this thread
1 guest


 
 
Adblock breaks this site