Thread: Whats best way to loop a program?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    USA
    Posts
    4

    Whats best way to loop a program?

    I have a simple little program that I created to test a funtion that best goes back to the beginning of the code from the end. Any ideas?

    Heres just a simple program:
    Code:
    #include "stdafx.h"
    #include <iostream>
    
    int ReadNumber()
    {
        using namespace std;
        cout <<" Welcome to Jake's Calculator, enter in two numbers to be computed" << endl;
        cout <<" Answers will be shown in this form: Add, Subtract, Multiply, and Divide." << endl;
        cout <<" Enter numbers to calculate:" << endl;
        int x;
        cin >> x;
        return x;
    }
    void WriteAnswer(int x)
    {
        using namespace std;
        cout <<"The answer is " << x << endl;
    }
    int main()
    {
        int x = ReadNumber();
        int y = ReadNumber();
        WriteAnswer(x+y);
        WriteAnswer(x-y);
        WriteAnswer(x*y);
        WriteAnswer(x/y);
        system("pause") // What to do from here to loop to top?
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    look into do-while or just while loops. google and this site's tutorials are an excellent source of information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loop-- not sure whats wrong
    By jamort in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2009, 11:34 PM
  2. Whats wrong with this program?!?!?
    By johnh444 in forum C++ Programming
    Replies: 5
    Last Post: 06-30-2004, 11:20 AM
  3. Whats wrong with my C program?
    By Golden Bunny in forum C Programming
    Replies: 16
    Last Post: 07-03-2002, 09:58 AM
  4. Whats wrong w/ my loop?? Please help?
    By aspand in forum C Programming
    Replies: 6
    Last Post: 05-30-2002, 03:42 AM
  5. Whats wrong with my loop?
    By Ruflano in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2002, 09:50 PM