What's wrong with my code?
#1
Posted 06 February 2012 - 07:01 PM
Register to Remove
#2
Posted 07 February 2012 - 11:22 PM
This line throws an error: int i = k + 1;
because k is not declared before being used.
This line: cout << i++ <<_<< endl;
is missing an expression, you could do it like this: cout << i++ << "" << endl;
You can't redeclare the variable i again as it was already declared, use another variable name instead: int i = 1;
Note: It's always a good idea to initialize your variables before using it in a computation.
Here is a working sample based on your code:
/* * File: test.cpp */ #include <iostream> using namespace std; int main() { int i = 0; // declaration and initialization i = i + 1; cout << "sum of i:" << i << endl; int x = 1; // declaration and initialization, another variable cout << "value of x:" << x << endl; return 0; }
Proud graduate of WTT Classroom
The help we provide here is free, however, if you wish to donate, you can do so here: http://www.whatthetech.com/donate/
ASAP and UNITE member
________________________________________________
!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users