# Thread: float; double; int

1. ## float; double; int

I can not enter dollar amounts with decimals at chk amt. I can't use float or double chk[SIZE] instead of int chk[SIZE]. What can I do?

#include <iostream.h>
#include <math.h>
#include <iomanip.h>

//Lyanette Scott CIS120

int main()
{
float b;
const int SIZE=100;
int chk[SIZE];
float dep;
int totchk=0;
int numchk;
float nbal;

cout << " Program to compute simple interest an amount\n"<< endl;
cout << "Enter the amount of the deposit ( no \$ or comma)"<< endl;
cin >> dep;
cout <<"Beginning balance" << endl;
cin>> b;
cout <<"How many checks for deposit" << endl;
cin>> numchk;

for (int i=1; i<=numchk; ++i)

{
cout<< "chk amt (enter zero when complete)"<<i<< ":" ;//checks
cin >> chk[i];
totchk += chk[i];
if (chk[i]==0) goto next;

}
next:cout << "Total amt in Checks: \t\$"<<totchk<<endl;

nbal=(b+dep)-(totchk+30);

cout << "Available balance: \t\$"<< nbal<< endl;

return 0;

}

HELP!!!!!!!!

2. >>> What can I do?

1. Learn to use code tags!

2. Think of your values as integer numbers of cents, and scale accordingly. \$1.00 = 100c.

3. ## ~

Don't use goto

4. >>> Don't use goto

! Because it wasn't formatted, I didn't bother reading the code - wow, I haven't seen one of those for years.

<fx> whistles loudly

Here, come and look at this guys!

5. Do you really need the checks to be in an array? At this point, you aren't re-displaying the check amounts, so you can just use a double variable to get the amounts. Also, since you are asking for the number of checks, the user shouldn't have to enter zero to finish. Once the number of checks has been entered, the loop should end (getting rid of the goto). Something like this:

Code:
```double chkamt; //instead of int chk[SIZE];

cout <<"How many checks for deposit" << endl;
cin>> numchk;

for (int i=1; i<=numchk; ++i)

{
cout<< "chk amt "<<i<< ":" ;//checks
cin >> chkamt;
totchk += chkamt;
}```

Popular pages Recent additions