You are viewing our Forum Archives. To view or take place in current topics click here.
C++ Help With Basic Variables
Posted:

C++ Help With Basic VariablesPosted:

Pkmonkey85
  • Junior Member
Status: Offline
Joined: Mar 21, 201113Year Member
Posts: 96
Reputation Power: 4
Status: Offline
Joined: Mar 21, 201113Year Member
Posts: 96
Reputation Power: 4
Ok im really new to C++ and i dont understand why my code wont work can someone help me?



// operating with variables

#include <iostream>

using namespace std;

int main ()
{
// declaring variables:
int a, b;
int result;

//process:
a = 5;
b = 2;
a = a + 1;
result = a - b;

//printed out result:
; cout << result

//terminate the program:

; system ("PAUSE");
return EXIT_SUCCESS;
}

When ever it runs it always says "4Press any key to continue"
How do i make the "press anything to continue" on the next line?
#2. Posted:
-Jordan-
  • TTG Addict
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 2,684
Reputation Power: 122
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 2,684
Reputation Power: 122
Pkmonkey85 wrote Ok im really new to C++ and i dont understand why my code wont work can someone help me?



// operating with variables

#include <iostream>

using namespace std;

int main ()
{
// declaring variables:
int a, b;
int result;

//process:
a = 5;
b = 2;
a = a + 1;
result = a - b;

//printed out result:
; cout << result

//terminate the program:

; system ("PAUSE");
return EXIT_SUCCESS;
}

When ever it runs it always says "4Press any key to continue"
How do i make the "press anything to continue" on the next line?


add

cout << "\n";

before the system("PAUSE");
#3. Posted:
Derp
  • TTG Senior
Status: Offline
Joined: Jan 24, 201014Year Member
Posts: 1,478
Reputation Power: 106
Status: Offline
Joined: Jan 24, 201014Year Member
Posts: 1,478
Reputation Power: 106
You could do what Jordan said, or just do

cout << result << endl;


Also, if you're wanting your program to work on other OSes such as Linux, it's better to use "cin.get()" instead of "System("PAUSE");".


Last edited by Derp ; edited 1 time in total
#4. Posted:
-Jordan-
  • TTG Addict
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 2,684
Reputation Power: 122
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 2,684
Reputation Power: 122
-Derp wrote You could do what Jordan said, or just do

cout << result << endl;

This is probably a better solution
#5. Posted:
Pkmonkey85
  • Junior Member
Status: Offline
Joined: Mar 21, 201113Year Member
Posts: 96
Reputation Power: 4
Status: Offline
Joined: Mar 21, 201113Year Member
Posts: 96
Reputation Power: 4
YES that worked thanks sooo much
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.