Jump to content

Build Theme!
  • Infected?


Hey there! :wub: Looks like you're enjoying the discussion, but you're not signed up for an account. When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. You can like posts to share the love. :D Join 92767 other members! Anybody can ask, anybody can answer. Consistently helpful members may be invited to become staff. Here's how it works. Virus cleanup? Start here -> Malware Removal Forum.

Try What the Tech -- It's free!


What's wrong with my code?

  • Please log in to reply
1 reply to this topic

#1 effinit


    New Member

  • New Member
  • Pip
  • 1 posts

Posted 06 February 2012 - 07:01 PM

#include <iostream> using namespace std; int main() { int i = k + 1; cout << i++ << << endl; int i = 1; cout << i++ << << endl; return 0; }


Register to Remove

#2 inzanity



  • Malware Team
  • 2,340 posts

Posted 07 February 2012 - 11:22 PM

Hi :welcome:

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



Related Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users