Thread: How to return to the start of a program/ a specific point of a program

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    1

    How to return to the start of a program/ a specific point of a program

    Hi, first of all, I apologise for anything wrong, a newbie around the corner. I had just started programming a few days ago so I wanted to try some programming to digest further.

    I was wondering if I could return myself to the start of the program or a specific point of a program. So, I asked a question somewhere else and a solution the contributor came up with was class (I haven't go through that section prior to this). I looked up here (my primary source) and..couldn't understand much about it..

    This is the code provided by contributor

    Code:
    int main()
    {
           MyClass* class = 0;
           do{
                class = new MyClass();
                delete class; //important
                //ask user to repeat
              } while (userChoice == 'y');
            
           return 0;
    }


    Code:
    #include <iostream>  //to let the compiler to see the cout
    #include <cstdlib>   //to let the compiler to see the rand()
    #include <ctime>     //to let the compiler to see the srand()
    
    
    using namespace std;
    
    
    int main()
    {
        cout << "Hello! To the future Businessmen/women! This is just a mock program for you to  check your business skills \n\n";
        cin.ignore();
    
    
        cout << "Now, your shop has 3 items that are going to be sold and those are...\n";
        cout << "1. USB (4.0 GB)" << "\n" << "2. Headphone (Stars)" << "\n" << "3. Logitech Optical Mouse \n";
        cin.ignore();
    
    
        cout << "And you have a capital of RM 5000" << "\n\n";
        cin.ignore();
    
    
        int USB, Headphone, Mouse;
        float Capital, Price_USB, Price_Headphone, Price_Mouse, Cost_USB, Cost_Headphone, Cost_Mouse;
    
    
        Capital = 5000.00;
        Price_USB = 20.00;
        Price_Headphone = 12.50;
        Price_Mouse = 15.00;
    
    
        cout << "So, before we begin our operations, may I ask how much stocks have you ordered  for each items for this week?" << "\n\n";
        cin.ignore();
    
    
        cout << "For USB (4.0 GB) [The cost for 1 USB (4.0 GB) is RM " << Price_USB << " ] ? ";
        cin >> USB;
        Cost_USB = (USB)*(Price_USB);
    
    
        cout << "\n\n";
        cout << "For Headphone (Stars) [The cost for 1 Headphone (Stars) is RM " << Price_Headphone << " ] ? ";
        cin >> Headphone;
        Cost_Headphone = (Headphone)*(Price_Headphone) ;
    
    
        cout << "\n\n";
        cout << "For Logitech Optical Mouse [The cost for 1 Logitech Optical Mouse is RM " << Price_Mouse << " ] ?  ";
        cin >> Mouse;
        Cost_Mouse = (Mouse)*(Price_Mouse);
    
    
        cout << "\n\n";
        cout << "So, the total cost for this week is " << ( (Cost_Headphone) + (Cost_Mouse) + (Cost_USB) ) << "." << "\n";
        cout << "And your remainder is RM" << ( (Capital) - ( (Cost_Headphone) + (Cost_Mouse) + (Cost_USB) ) ) << "." << "\n\n";
    
    
        int Yes_or_No, Number_of_workers, Wage, Total_wage;
    
    
        Wage = 120.00;
    
    
        cout << "Do you hire worker(s) (ENTER 0 for NO and 1 for YES)? \n";
        cin >> Yes_or_No;
    
    
        if ( Yes_or_No ==1) {
            cout << "How many (Wage for worker(s) is RM 120.00 per week)? ";
            cin >> Number_of_workers;
            Total_wage = (Number_of_workers)*(Wage);
        }
    
    
        cout << "\n\n";
        cout << "So, shall we start our operations for this week? (ENTER 1 to START and 0 to CHECK your settings)";
    
    
    }
    That is where I am currently now in progress...

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Code:
    do
    {
        //Your code
        char userChoice;
        std::cout<<"Try Again?";
        std::cin>>userChoice;
    }while(userChoice=='y');

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-14-2012, 09:43 AM
  2. Get program to copy itself into program files, then start on startup.
    By guitarist809 in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2008, 09:42 AM
  3. Replies: 2
    Last Post: 10-23-2007, 04:27 PM
  4. Start and kill program from within program
    By System_159 in forum Windows Programming
    Replies: 4
    Last Post: 09-10-2007, 04:01 PM
  5. is there a way of checking what program uses a specific port?
    By Xterria in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-27-2004, 10:54 PM