Like Tree1Likes
  • 1 Post By manasij7479

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

This is a discussion on How to return to the start of a program/ a specific point of a program within the C++ Programming forums, part of the General Programming Boards category; Hi, first of all, I apologise for anything wrong, a newbie around the corner. I had just started programming a ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Code:
    do
    {
        //Your code
        char userChoice;
        std::cout<<"Try Again?";
        std::cin>>userChoice;
    }while(userChoice=='y');
    福恩何 likes this.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-14-2012, 10: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, 05:27 PM
  4. Start and kill program from within program
    By System_159 in forum Windows Programming
    Replies: 4
    Last Post: 09-10-2007, 05: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, 11:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21