Hello all,

I got problem to write program concerning in money deposit into bank.

i.e : money = 100$, month = 3, interest = 3%/month

here we got :
1- Enter money into bank = 100
2- Enter month = 3
3- Total amount = 109.27
4- Total interest = 9.27

here what I wrote and it got error :

#include <iostream.h>
#include <conio.h>
void main(){
clrscr();
int money=1, month=1, sum=0;
cout<<"Enter money into bank ="; cin>>money;
cout<<"Enter month ="; cin>>month;
while (month<=12){
sum = money + money * 3/100
cout<<"Total amount ="<<sum;
cout<<Total interest ="<<sum - money;
}
return 0;
}

Could anyone help me to fix this ?

Thanks in avance.

Integers are only capable of representing whole numbers.

Have a look what happens when you do this (Remember that both 3 and 100 are integers)

cout << 3/100 ;

change your variables from type int to type double, and change your 3/100 to double's - ie, 3.0 / 100.0 Also, what compiler are you using? your header files and main declaration are wrong by the C++ standard. If you're on a modern compiler, change it to this -

#include <iostream>  //No ".h" extension for standard headers

//...

int main()  // main always returns an int
{

//...

I use Turbo C++, and it always works with <iostream.h>
void main ()

by the way, I think it is caused by error caculation or sth like that.

Thanks

I use Turbo C++, and it always works with <iostream.h>
void main ()

by the way, I think it is caused by error caculation or sth like that.

Thanks

Assuming you mean the MS-DOS based old borland Turbo C++ compiler from the mid-90s (Which pre-dates the language standard, and misses out alot of modern language features), then I reccomend getting a modern compiler.

It would help if you said what the error was, too.

Also, look at this - you have an infinite loop, and a missing double-quote mark(bold)

while (month<=12){
    sum = money + money * 3/100
    cout<<"Total amount ="<<sum;
   [B] cout<<Total interest ="<<sum - money;[/B]
}

I think I got error in condition, ok let me tell you more about what it got error.

when I use while (month<=12) {
sum = money + money * 3/100
cout << "Total amount ="<<sum;
}

it runs non stop and the result show me only 1st month = 103 but I want to get total amount of 3 month that is $109.27.

Could you help me ?

Thanks

Its running non-stop because the same bit of code is repeating all the time that month<=12 is true.

You need to add something into the non-stop-repeating block of code, which changes month, so that eventually the condition becomes false.

while(month<=12), the loop runs 12 times

Not quite - month never changes - which gives two possibilities:

- Month starts out greater than 12, and the loop doesn't even start
- Month starts out less than or equal to 12, and the loop repeats forever

This article has been dead for over six months. Start a new discussion instead.