online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** harpreet singh Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> using namespace std; void printNumber(int num); int main() { int r; int starRows; // --- Loops 1-4 rewritten using 'do-while' loops --- cout << "1. For loop to display the numbers 1 to 25:\n\n"; r = 1; do { printNumber(r); r++; } while (r <= 25); cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n2. For loop to display the numbers 2 to 8\n\n"; r = 2; do { printNumber(r); r++; } while (r <= 8); cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n3. For loop to display the numbers 50 to 100\n\n"; r = 50; do { printNumber(r); r++; } while (r <= 100); cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n4. For loop counting from 1 to 75 by 4\n\n"; r = 1; do { printNumber(r); r += 4; } while (r <= 75); cout << "\n\n-----------------------------------------------------------------------------"; // --- Loops 5-15 kept as 'for' loops --- cout << "\n\n5. For loop counting from 36 to 600 by 15\n\n"; for (r = 36; r <= 600; r += 15) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n6. For loop counting from -25 to 105 by 7\n\n"; for (r = -25; r <= 105; r += 7) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n7. For loop counting from -350 to 350 by 8\n\n"; for (r = -350; r <= 350; r += 8) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n8. For loop counting from 100 to 1 by 1\n\n"; for (r = 100; r >= 1; --r) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n9. For loop counting from 1000 to 700 by 5\n\n"; for (r = 1000; r >= 700; r -= 5) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n10. For loop counting from 180 to -50 by 6\n\n"; for (r = 180; r >= -50; r -= 6) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n11. For loop counting from -30 to -600 by 25\n\n"; for (r = -30; r >= -600; r -= 25) { printNumber(r); } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n12. For loop to display even numbers between 1 and 200 including 200\n\n"; for (r = 1; r <= 200; r++) { if (r % 2 == 0) { printNumber(r); } } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n13. For loop to display odd numbers between 200 and 300 inclusive\n\n"; for (r = 200; r <= 300; r++) { if (r % 2 != 0) // Using != instead of == 1 { printNumber(r); } } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n14. For loop to display the numbers between 1 and 400 that are divisible by 7\n\n"; for (r = 1; r <= 400; r++) { if (r % 7 == 0) { printNumber(r); } } cout << "\n\n-----------------------------------------------------------------------------"; cout << "\n\n15. For loop to display the numbers between 1 and 500 that are equally divisible by both 6 and 4\n\n"; for (r = 1; r <= 500; r++) { if (r % 6 == 0 && r % 4 == 0) // Using the && operator { printNumber(r); } } cout << "\n\n-----------------------------------------------------------------------------\n\n"; // --- THIS IS THE "DOWNER ONE" --- I have not changed it --- // For loop to create a design using stars cout << "16. Dollor pattern!\nHow many rows of dollor do you want in your pattern?\nEnter choice: "; cin >> starRows; cout << endl; // Loop to print the top half of the pattern for (int i = 1; i <= starRows; ++i) { for (int j = 1; j <= i; ++j) { cout << "$"; } cout << endl; } for (int i = starRows - 1; i >= 1; --i) { for (int j = 1; j <= i; ++j) { cout << "$"; } cout << endl; } return 0; } void printNumber(int num) { std::cout << num << "\t"; // Using std::cout for variety }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue