• Log in or sign up for an account here: https://www.sythe.org/login

What went wrong?

booyaboy234

Newcomer
Joined
Aug 7, 2008
Sythe Gold
0
Messages
8
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;
}
 
Le Monkey
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
int integer;
should be int square
 
Code:
 cout << square << end];
Shouldn't that be endl?
 
Member of the Month Winner
Sythe's 10th Anniversary
I actually didn't need that line at all.
and thanks alot SMR
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?)
 
Le Monkey
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
C++ doesn't use ^ for exponents. But there's pow() in math.h.
 
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?)

sorry, i meant the "end]" part
 
Member of the Month Winner
Sythe's 10th Anniversary
sorry, i meant the "end]" part
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)
 
Le Monkey
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
NP. Also, printf_s*
 
Runescape Gamblingrunescape gambling
Back
Top