Thread: How to do correct month order

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    5

    Post How to do correct month order

    This is my assignment

    100.PNG - Google Drive

    Capture 200.PNG - Google Drive

    how I create months in right order



    this is my code :
    Code:
    #include <iostream>
    using namespace std;
    
    
    int main ()
    {
        int an1,bb1,tm,i,mn1;
        double in1;
        double q1;
        double qq1;
        double qqq1;
        double q2;
        double q3;
        double ad=0;
        double aw=0;
        int f1=1;
        int f2;
        int fo=1;
        int yn=1;
        int mn=1;
        double z;
        int ynl=1;
        //account 01
        cout << "Enter your account number : ";
        cin >> an1;
        while(an1<1000 || an1>9999)
        {
        cout << "Enter your account number : ";
        cin >> an1;
        }
    
    
        cout << "Enter your account beginning balance: ";
        cin >> bb1;
        while(bb1<0 || bb1>100000)
        {
        cout << "Enter your account beginning balance: ";
        cin >> bb1;
        }
        cout << "Enter your account interest rate: ";
        cin >> in1;
        while(in1<0 || in1>0.15)
        {
        cout << "Enter your account interest rate: ";
        cin >> in1;
        }
    
    
        // term the account
        cout << "Enter a term the accounts will be held: ";
    
    
        cin >> tm;
        while(tm<0 || tm>10)
        {
        cout << "Enter a term the accounts will be held: ";
        cin >> tm;
        }
        cout << "Enter an automatic deposit amount per month: ";
        cin >> ad;
        cout << "Enter an automatic withdrawal amount per month : ";
        cin >> aw;
    
    
    
    
        q1=in1/12;
        f2=tm*12;
        q2=bb1;
    
    
        for (i=1;i<=f2;++i)
            {cout << "Year number : " << ynl << "\n";
            cout << "Month number : " << mn << "\n";
            cout << "Month-starting balance : " << q2 << "\n";
            z=q2+(q1*i)+(ad-aw);
            cout << "Month-ending balance : " << z << "\n";
            if (i>=0 && i <=11)
            {
                ynl=1;
            }
            else if (i>=12 && i <=23)
            {
                ynl=2;
    
    
            }
            else if (i>=24 && i <=35)
            {
                ynl=3;
    
    
            }
            else if (i>=36 && i <=47)
            {
                ynl=4;
            }
            else if (i>=48 && i <=59)
            {
                ynl=5;
            }
            else if (i>=60 && i <=71)
            {
                ynl=6;
            }
            else if (i>=72 && i <=83)
            {
                ynl=7;
            }
            else if (i>=84 && i <=95)
            {
                ynl=8;
            }
            else if (i>=96 && i <=107)
            {
                ynl=9;
            }
            else
            {
                ynl=10;
            }
            cout << " ------------------------------ " << "\n";
            mn=mn+1;
            q2=z;
            z=z+(q1*i)+(ad-aw);
            }
    
    
          return 0;
    }
    Please help me !!!!!!!!!!!!!!!!!!!!!!!!!!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,271
    I am afraid that this is not good at all:
    Code:
    int an1,bb1,tm,i,mn1;
    double in1;
    double q1;
    double qq1;
    double qqq1;
    double q2;
    double q3;
    double ad=0;
    double aw=0;
    int f1=1;
    int f2;
    int fo=1;
    int yn=1;
    int mn=1;
    double z;
    int ynl=1;
    Keep in mind:
    • Your variable names should be descriptive. This means names like account_number, not an1, and account_beginning_balance, not bb1. You should not have single letter variable names except for loop indices (in which case they would typically have a very limited scope, i.e., limited to the loop).
    • Variables should be declared near first use. That is, declare variables at the point when you can initialise them suitably, or if you cannot initialise them per se, then at the point nearest to where you can otherwise provide them with a sensible initial value.
    • If you are repeating the same name, but with numbers, then maybe you should consider using an array or some other suitable container.

    Additionally, you should break up your main function into smaller functions that do one thing and do it well.

    You also need to indent your code more consistently.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,537
    Ok, so where do you have a BankAccount structure?

    Variable names like q1,qq1,qqq1,q2,q3 are meaningless.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2019
    Posts
    5
    Okay.I got it.Thank for advice me.I'm a beginner so I don't know about it. Next time I will not do like that.

  5. #5
    Registered User
    Join Date
    May 2019
    Posts
    5
    Yes.There is not any useful variables.

  6. #6
    Registered User
    Join Date
    May 2019
    Posts
    5
    When I run this file all outputs are work correctly.but month order isn't work correctly.After 12 it should be 1.Can you say to me how I correct it first.....

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,537
    Examine this loop
    Code:
    for ( int i = 0 ; i < 120 ; i++ ) {
      int month = (i % 12) + 1;
      int year = (i / 12) + 1;
      cout << "Year=" << year << ", month=" << month << endl;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    May 2019
    Posts
    5
    Thank you !!!!
    It's work.......................
    Thank you very much for youuuuuuu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help printing values in the correct order
    By cspctec in forum C Programming
    Replies: 1
    Last Post: 11-18-2014, 09:08 PM
  2. Replies: 1
    Last Post: 11-17-2012, 05:34 PM
  3. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  4. Replies: 4
    Last Post: 03-06-2008, 03:38 PM
  5. correct order to insert new node?
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2004, 07:51 PM

Tags for this Thread