| | |
confirmation of LOOP
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 12
Reputation:
Solved Threads: 1
hey guyz!!! i'm just trying to check my code u all if it's correct. thankz!
the problem is " ask a number (N). calculate and display the value of x, where x = (1*N)+(2*N)+(3*N)...(N*N);
ex. if i input a number 5 the formula of x where: x = (1*N)+(2*N)+(3*N)+(4*N)+(5*N);
this is my code:
the problem is " ask a number (N). calculate and display the value of x, where x = (1*N)+(2*N)+(3*N)...(N*N);
ex. if i input a number 5 the formula of x where: x = (1*N)+(2*N)+(3*N)+(4*N)+(5*N);
this is my code:
C++ Syntax (Toggle Plain Text)
#include <iostream> int main () { int n,x,y; y=0; cout<<"\nEnter number: "; cin>>n; while (y<=n) { cout<<"\n"<<y; y++; x += (y*n); } cout<<"\n\nx = "<<x; return 0; }
Last edited by Ancient Dragon; Aug 20th, 2007 at 10:12 pm. Reason: add code tags
>>i'm just trying to check my code u all if it's correct
does it do what its supposed to do ? If yes, then its ok. If not then you need to fix it. One problem though is that your program will produce data overflow errors if the value of n is too large.
does it do what its supposed to do ? If yes, then its ok. If not then you need to fix it. One problem though is that your program will produce data overflow errors if the value of n is too large.
Last edited by Ancient Dragon; Aug 20th, 2007 at 10:15 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
The value of x is uninitialized, and the value of y should start at 1 not 0. It might be better to use a for loop instead of a while loop.
Last edited by Ancient Dragon; Aug 20th, 2007 at 10:31 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the C++ Forum
- Previous Thread: syntax error before '::' token
- Next Thread: C++ and MySql
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






