# Thread: How to do correct month order

1. ## 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 !!!!!!!!!!!!!!!!!!!!!!!!!!!   Reply With Quote

2. 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.  Reply With Quote

3. Ok, so where do you have a BankAccount structure?

Variable names like q1,qq1,qqq1,q2,q3 are meaningless.  Reply With Quote

4. 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.  Reply With Quote

5. Yes.There is not any useful variables.   Reply With Quote

6. 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.....   Reply With Quote

7. 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;
}```  Reply With Quote

8. Thank you !!!!
It's work.......................
Thank you very much for youuuuuuu  Reply With Quote

Popular pages Recent additions #### Tags for this Thread

c++, c++ beginner, c++ beginners, cout, double 