BleepingComputer.com: Programming in C++

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Programming in C++

#1 User is offline   Benjytim 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 3
  • Joined: 15-October 10

Posted 01 November 2010 - 03:31 AM

I ran this program in my compiler and it ran but the output-screen does not stay for me to see. what could be wrong with the program?

#include<iostream.h>
main()
{
int i=5, j=6, k=7, n=3;
cout<<i+j*k-k%n<<endl;
cout<<i/n<<endl;
system ("pause")
return 0;
}

This post has been edited by hamluis: 01 November 2010 - 09:46 AM
Reason for edit: Moved from XP forum to Programming ~ Hamluis.


#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 01 November 2010 - 12:20 PM

Don't run your program from the IDE, run it from the command line.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   NicoDev 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 41
  • Joined: 18-October 10
  • Gender:Male
  • Location:France

Posted 01 November 2010 - 03:29 PM

Hello

You can use getchar(); instead of system ("pause")

Nico

#4 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 03 November 2010 - 05:39 PM

The code is all wrong.

- You have one semi-colon missing after system("pause")
- You are using <iostream.h> which is deprecated.
- The main() function should have an int return type.
- You are not using any namespace before cout and endl, like std::cout.

How did you compile it in the first place?

#5 User is offline   kanraku 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 10
  • Joined: 08-November 10
  • Gender:Male
  • Location:Canada

Posted 09 November 2010 - 12:58 AM

He probably didn't compile at all, but that wouldn't explain the output screen...

Besides the DOS screen just running without compiling anything.

Maybe, he's not using an IDE?

A namespace for cout is missing.
Main is missing a type.

#6 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 09 November 2010 - 05:27 PM

Quote

He probably didn't compile at all, but that wouldn't explain the output screen...


It probably displayed an error and then quit. You can see the exact same behavior if you go to your run box in the start menu and just type in ipconfig.exe. A box will display for a fraction of a second and then close. Same thing.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users