User Tag List

Results 1 to 1 of 1

Thread: Loop Master Program in C++

  1. #1
    Loop Master Program in C++

    User Info Menu

    Loop Master Program in C++

    This program will ask you for two numbers and then ask for a loop type. Look at the source code to see how it works:
    C++
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main()
    {
        int num1, num2, loop;
        cout << "Input the start of your loop: ";
        cin >> num1;
        system("CLS");
        cout << "Input the end of your loop: ";
        cin >> num2;
        system("CLS");
        cout << "Select loop type:\n\n1 - For\n2 - While\n3 - Do\n\n";
        cin >> loop;
        system("CLS");
        if (loop == 1)
        {
            for (num1; num1 < num2 + 1; num1++)
            {
                cout << num1 << "\n";
            }
        }
        else if (loop == 2)
        {
            while (num1 != num2 + 1)
            {
                cout << num1 << "\n";
                num1++;
            }
        }
        else if (loop == 3)
        {
            do
            {
                cout << num1 << "\n";
                num1++;
            } while (num1 != num2 + 1);
        }
        else
        {
            cout << "Invalid selection >: |\n\n";
        }
        system("PAUSE");
        system("CLS");
        return main();
    }

    UPDATE, C code added:

    Code:
    #include <stdio.h>
    
    int num1, num2, loop;
    
    int main()
    {
        printf("Enter the start of your loop: ");
        scanf("%d", &num1);
        system("cls");
        printf("Enter the end of your loop: ");
        scanf("%d", &num2);
        system("cls");
        printf("Select your loop:\n\n1 - For\n2 - While\n3 - Do While\n\n");
        scanf("%d", &loop);
        system("cls");
        if (loop == 1)
        {
            for (num1; num1 < num2 + 1; num1++)
            {
                printf("%d\n", num1);
            }
        }
        else if (loop == 2)
        {
            while (num1 != num2 + 1)
            {
                printf("%d\n", num1);
                num1++;
            }
        }
        else if (loop == 3)
        {
            do
            {
                printf("%d\n", num1);
                num1++;
            } while (num1 != num2 + 1);
        }
        else
        {
            printf("Invalid selection >: |\n\n");
        }
        getch();
        system("cls");
        return main();
    }
    Last edited by -LeetGamer-; 07-11-2010 at 05:13 AM.

    If you have an idea on a PSP related program that is ran on Windows PM me with some information on your idea please.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •