can anyone tell me what is wrong with my code?
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
void input();
void compute();
void print();
char name[6][21];
float previous_balance [6];
float payments [6];
float charges [6];
void main()
{
input();
}
void input()
{
for (int counter=0; counter<6; counter++)
{
cout<<"Enter the last name for the "<<counter+1<<" customer."<<endl;
cin>>name[counter];
cout<<"Enter the previous balance for customer "<<name[counter]<<endl;
cin>>previous_balance [counter];
if (isdigit(previous_balance[counter])==0)
{
cout<<"Cannot contain letters."<<endl;
counter--;
}
}
}
sorry that the code looks abit messy. What I do not understand is, why it give me this when I typed a letter for cin>>previous_balance
Enter the last name for the ... customer
.
.
.
.
.
it will just flood the screen and keep repeating the same sentence above. I know that previous balance is a float, but i am just checking it to make sure it is really entered as a float. I have tried putting cin.get(): before every cin. However, it still give me the same problem.