Thread: Some problem with my program

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    Some problem with my program

    Hi,

    I have a problem with my program. I am making a program on C++ which is about a "fare calcuation system".

    I have made the program completely, but I wanted to know that how to use a "looping" in it?


    The formula that I have made for fare calculation is:

    total fare = tax+fare.

    I have also defined the variable for this as:

    int tax;
    int fare;
    int total fare;
    total fare = tax+fare
    tax = fare * 1/100



    This is the portion of the program that I have made:

    --------------------------------------------------------------------

    Code:
    
    
    int main()
    
    {
    
    int tax;
    int fare;
    int total fare;
    int y;
    int n;
    
    
    
    
    
    if (fare <=1000)
    
    { 
    
    cout<<"fare:"; cout<<fare<<"\n";
    
    cout<<"tax:"; cout<<tax<<"\n";
    
    cout<<"-------------------------------------"<<"\n";
    
    cout<<"totalfare:"; cout<<totalfare<<"\n";
    
    cout<<"Do you want to calculate for another person?"<<"\n"; 
    cout <<"Enter Y for yes and N to exit>:";
    cin >> y;
    cin >> n;
    
    }
    
    }
    
    
    Total fare = tax+ fare.

    After this fare is calculated, I have added the option saying:
    "do you want to calculate for another person"?

    I wanted to know that how can I continue this process ,once the user chooses "y" for "yes" ?

    How can I use the loop option to make this continue once the "y" is
    entered?

    I hope my question is clear

    Thanks

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    For the syntax, refer to the tutorials on the site.
    For the logic, a flowchart is an ideal tool for this job. It doesn't take long to learn and it's an ideal tool for things such as this.
    You should also indent your code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't hand out solutions!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    Elysia is right, you should refer to your tutorials.
    And indenting the code is very good for readibility, if you had 100's of lines of code without indenting, how are you ever going to find what goes with what

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Well, Their is one more thing I wanted to know that in C++ , can we put the variables inside the Main() so that the statement can be called later on ?

    Just give me some hint, so I can do it

    I have gone through the syntax but I am confused between functions like "loop" and "return" .




    I hope I am clear
    Last edited by student111; 11-08-2011 at 02:35 AM. Reason: adding more

  6. #6
    spaghetticode
    Guest
    Okay, some hint: Forget about the loop for a while and get the rest straight for only one calculation. You still got a lot to work on. Take care especially of the following: naming rules for variables, defining variables, input and output.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with program.
    By EmaZek in forum C Programming
    Replies: 10
    Last Post: 04-28-2011, 01:03 PM
  2. CS1 Program (New Problem)
    By DaNxTh3xMaNx in forum C Programming
    Replies: 3
    Last Post: 09-30-2010, 02:04 AM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM
  5. Some Problem With My Program
    By Americano in forum C Programming
    Replies: 5
    Last Post: 10-18-2003, 01:58 AM