Here is the problem i Designed a program to collect blood from users after collecting the data i give them the output. one of the output is retrieved from outside function which is getTotalAmount but i am getting error: too few arguments to function 'float getTotalAmount'. code attached below :
class BloodDonator{
private:
string bloodtype ,name;
float amount ;
public:
void set_details(){
cout<<"Enter Name :";
cin>>name;
cout<<"Please select a blood type ...\n";
cout<<" Enter [1] for A positive\n";
cout<<" Enter [2] for A negative\n";
cout<<" Enter [3] for B positive\n";
cout<<" Enter [4] for B negative\n";
cout<<" Enter [5] for O positive\n";
cout<<"Enter [6] for O negative\n";
cout<<"Enter [7] for AB positive\n";
cout<<"Enter [8] for AB negative\n";
cin>>bloodtype;
cout<<"Enter Amount (ml) :";
cin>>amount;
};
float getAmount(){
return amount;
};
string getName(){
return name;
};
string getBloodType(){
return bloodtype;
};
getTotalAmount(float &amount);
string n(){return name;}
};
float getTotalAmount(BloodDonator *ps)
{
static float totalamount=0;
totalamount = totalamount + ps->getAmount();
return totalamount;
};
int main()
{
BloodDonator p1 ;
//float getTotalAmount();
//getTotalAmount();
for(int i=0;i<3 ;i++){
cout<<" Input Details\n";
cout<<"------------------------------\n";
p1.set_details();
//p1.getTotalAmount(*p1.getAmount());
cout<<"------------------------------\n";
cout<<" output Details\n";
cout<<"------------------------------\n";
cout<<"name :"<<p1.n()<<endl;
cout<<"blood type :"<<p1 .getBloodType()<<endl;
cout<<"Blood Amount :"<<p1.getAmount()<<endl;
cout<<"Total Amount of Blood Donated so far :\n"<<getTotalAmount()<<endl;//here is total amount of blood
}
return 0 ;
}
You may have to change the following segments of your code:
// it's ok
cout<<"name :"<<p1.n()<<endl;
// removed space between "p1." and "getBloodType()"
cout<<"blood type :"<<p1.getBloodType()<<endl;
// it's ok
cout<<"Blood Amount :"<<p1.getAmount()<<endl;
// passed pointer to p1, cause getTotalAmount() expects a pointer to BloodDonator object.
cout<<"Total Amount of Blood Donated so far :\n"<<getTotalAmount(&p1)<<endl;
Your code has several more problems like:
What is the job of getTotalAmount(float &amount); inside BloodDonator class.
if BloodDonator has already getTotalAmount(float &amount);, then, why there is a float getTotalAmount(BloodDonator *ps) doing outside...
you're hardcoding blood donars detials, you should inject details through constructor...
etc...
Look at the declaration in the class:
getTotalAmount(float &amount);
And the call in main() (last cout statement):
getTotalAmount();
You need to pass a required pointer variable p1 (since that's relevant and compatible) to the getTotalAmount().
Also the explicit type is missing in the declaration, it defaults to int, beware of that. To prevent it, declare it correctly:
float getTotalAmount(float &amount);
Another problem, which is the definition of function. You've just declared a function getTotalAmount (non class member function), you actually didn't wrote definition of the class member function getTotalAmount, i.e. you've defined the same named functions in two places.
It's up to you to code only for the one required by you and delete the another. In the current code provided by you, the class member function getTotalAmount has no meaning.
There are a few problems but the fundamental issue is bad program design. Any time you use a static variable you should think hard whether you really need it. Especially as a beginner you will almost never really need to use static variables.
In your code you have a static variable inside getTotalAmount. Instead this variable should be in main (and non-static). And the calculation to add the total blood donated should also be in main. Like this
int main()
{
BloodDonator p1;
float totalAmount = 0.0f;
for (int i=0; i<3; i++) {
...
cout << "Blood Amount :" << p1.getAmount() << endl;
totalAmount = totalAmount + p1.getAmount(); //here is total amount of blood
cout << "Total Amount of Blood Donated so far :\n" << totalAmount << endl;
}
The function getTotalAmount can be deleted.
Related
I CAN NOT USE VECTORS FOR THE ASSIGNMENT
I have to create a structure that stores the following information: student name, id number, pointer to an array of test scores, average test score, letter grade.
The program should keep a list of test scores for a group of students. It should ask the user how many students are in the class and how many test scores there are.The number of test scores will be the same for every student. The program should dynamically allocate an array of structures. Each structures Tests member should point to a dynamically allocated array which will hold the test scores.
After the arrays have been dynamically allocated, the program should ask the user for the id number and all of the test scores for each student. The average score should be calculated and stored in the Average member of the structure. Display the student info.
I am having trouble when the user enters the test scores in the inputScores function. I can't figure out how to access the structure member right. Can you please look at my code and help me figure out what I'm doing wrong?
Here is my structure:
struct Grade
{
string name;
int idNum;
int* tests;
double average;
char grade;
};
Here are my functions:
//user enters number of students which is then used as the size of the dynamically allocated struct array
int inputStudents();
//user enters number of tests for each student which is then used as the size of the dynamically allocated array of test scores in the structure
int inputTests();
string inputName();
int inputID();
//user inputs scores for each student. this is a function i'm struggling with
int *inputScores(int *testScores, int numTests);
double calcAvg(int *testScores, int numTests);
char calcGrade(double);
void display(Grade*, int);
Here is my main:
int main()
{
Grade *studentList;
int size = inputStudents();
studentList = new Grade[size]; //dynamically create array of Grade struct
int numTests = inputTests(); //number of test scores stored in numTests
for (int i = 0; i < size; i++) //loop to store all student's info
{
studentList[i].name = inputName();
studentList[i].idNum = inputID();
studentList[i].tests = inputScores(studentList[i].tests, numTests, i);
studentList[i].average = calcAvg(studentList[i].tests, numTests);
studentList[i].grade = calcGrade(studentList[i].average);
}
display(studentList, size);
delete[] studentList;
return 0;
}
Here is the function i am struggling with. Every time I reference studentList a different error appears. My program won't even compile and I'm pretty sure this function is the reason why. Here I pass the tests structure member, rather than the entire structure. I also pass the number of tests and the counter from the loop in main that tells us which student the user is entering the test scores for.
int *inputScores(int *studentList, int numTests, int count)
{
cout << endl;
cout << "Enter the test scores:\n";
for (int i = 0; i < numTests; i++)
{
studentList[count].tests = new int[numTests]; //my error says the studentList must have a class type
cout << "Score " << (i + 1) << ": ";
cin >> studentList[count]->tests[i]; //my error says studentList must have a pointer type
cout << endl;
}
return studentList->tests; //my error says studentList must have a point-to-class type
}
You are passing a pointer to each student's test array to inputScores() but accessing it as a pointer to a student. You would have to change the inputScores() function as given below:
void inputScores(int *tests, int numTests, int count)
{
cout << endl;
cout << "Enter the test scores:\n";
for (int i = 0; i < numTests; i++)
{
cout << "Score " << (i + 1) << ": ";
cin >> tests[i];
cout << endl;
}
}
Also, I made one more modification. Its always better if the caller function allocates memory and pass a reference to the array. So we need to call the inputScores() function as given below
studentList[i].tests = new int[numTests];
inputScores(studentList[i].tests, numTests, i);
This is the output I received:
How many students are there?
3
How many tests does each student have?
2
Enter the student's name:
Joohn
Enter the student's ID number:
1
Enter the test scores:
Score 1: 12
Score 2: 13
Enter the student's name:
Jack
Enter the student's ID number:
2
Enter the test scores:
Score 1: 67
Score 2: 45
Enter the student's name:
Jill
Enter the student's ID number:
3
Enter the test scores:
Score 1: 56
Score 2: 89
--------------------------------------------------------
Here is all the info I have for each student:
Student #1:
Name: Joohn
ID Number: 1
Test Scores: Average Grade: 12
Letter Grade: F
Student #2:
Name: Jack
ID Number: 2
Test Scores: Average Grade: 56
Letter Grade: F
Student #3:
Name: Jill
ID Number: 3
Test Scores: Average Grade: 72
Letter Grade: C
--------------------------------------------------------
Your function inputScores is declared like this
int *inputScores(int *studentList, int numTests, int count)
which means studentList is a pointer to an int (which can be treated like an array). Later in the function, you attempt to do this:
studentList[count].tests = new int[numTests];
If studentList is an int* (or int array), then studentList[count] is just an int. You're trying to access the member variable tests of an int. But int is a primitive type.
When you called this function in main, you correctly passed an int*:
studentList[i].tests = inputScores(studentList[i].tests, numTests, i);
So treating the variable like it were actually an int * instead of a Grade * should solve the first of your problems. You should also change the name of the variable, since you're not really passing a studentList, it's more of a tests variable. That should help cut down on some of the confusion.
int *inputScores(int *tests, int numTests, int count)
After that, you'll realize that even through you're passing studentList[i].tests to your inputScores function, you'll have a memory leak and not be able to access the memory you thought you just filled. You DID fill memory, but when you tried to assign a new value to tests via tests = new int[numTests];, that only changed the local copy of tests.
To fix THAT problem, you need to pass tests by reference, like this:
int *inputScores(int*& tests, int numTests, int count)
That will allow any changes you make in your function to the int*, tests, to persist outside of the function.
In the code below I have a class called Market. With the data members and functions as shown. When the function shopkeeper(market &m , int i) is called , The compiler executes the the printing of "Name" and "Price" without taking the Name from user by gets().
class market
{
public:
char item;
double price, tax, total;
public:
market()
{
char* item;
price=0;
tax=0;
}
void shopkeeper(market &m, int i)
{
cout<<" Item number "<<i<<"\n ";
cout<<" ----------- "<<"\n";
cout<<"Name ";
gets(&(m.item));
cout<<" Price "<<endl;
cin>>m.price;
cout<<" Tax "<<endl;
cin>>m.tax;
}
The output us as follows:
item is a single char. If you read documentation of gets, that function receives a pointer to buffer you have to allocate, big enough to fit input, or an Undefined Behavior would happen.
Also, gets is a function which should no longer be used in C++. It also was removed from recent versions of language. You should use std::string and read it from std::cin like everything else.
In my code, I want to add one student info into my class pointer array and the array size will increase each time a new student is added. Here is my code:
My header file:
class Student{
public:
int studentID;
char studentName[20];
int currentEnrollment;
Student();
void AddStudent(Student *tempStudent[], int countStudent, int sizeOfArray);}
My Class definition file:
void Student::AddStudent(Student *tempStudent[], int countStudent, int sizeOfArray)
{
for (int i = countStudent; i < sizeOfArray; i++)
{
cout << "Please enter student id (4 digits only): ";
cin >> tempStudent[i]->studentID;
cout << "Please enter student name: ";
cin >> tempStudent[i]->studentName;
}
}
My Main.cpp file
int *totalStudent = new int;
*totalStudent = 1;
int i, j, countStudent = 0;
int sizeOfArray = *totalStudent;
Student *newStudent[*totalStudent];
//Each time a new student is added, I will allocate a new memory for the array element, then add student Info using function.
for (i = countStudent; i < *totalStudent; i++)
{
newStudent[i] = new Student;
newStudent[i]->AddStudent(newStudent, countStudent, sizeOfArray);
countStudent++;
*totalStudent++;
}
When I run my code, I get an undefined reference error, so I do not know If I am able to increase my array or not. I intend to use C++ syntax so I use new and delete. Thank you for your help.
P.S: Here is my new code and it runs great, the only missing is the studentID for the first element in array.
In my main class:
int numStudent = 0;
int i, j, countStudent = 1;
Student *newStudent = new Student[countStudent];
AddStudent(newStudent, countStudent, numStudent);
My Student.h
class Student{
public:
int studentID;
char studentName[20];
int currentEnrollment;
};
Student AddStudent(Student *newStudent, int &countStudent, int &numStudent);
and My Student.cpp
Student AddStudent(Student *newStudent, int &countStudent, int &numStudent)
{
Student tempStudent;
cout << "Please enter student id (4 digits only): ";
cin >> tempStudent.studentID;
cout << "Please enter student name: ";
cin >> tempStudent.studentName;
newStudent[numStudent] = tempStudent;
numStudent++;
if (numStudent == countStudent)
{
Student *newStudentSize = new Student[countStudent + 1];
for (int i = 0; i < numStudent; i++)
{
newStudentSize[i] = newStudent[i];
}
delete []newStudent;
return *newStudentSize;
countStudent += 1;
}
}
Running this code will give me the following result:
StudentID: 11
StudentName: Dat
StudentID: 23
StudentName: Michael
Printing:
StudentID: 0
StudentName: Dat
StudentID: 23
StudentName: Michael
While it doesn't make sense to increase the array for each new student (it's inefficient) here's one way you can do it (I didn't even try to make your code compile because it has a number of issues and is unnecessarily complicated). Note that tempStudent (in the code snippet below) doesn't even have to be created using new. This solution stores Student objects in the students array (although it's easy to modify it to store Student object pointers instead). That said, usually, you'll just want to create an array of large enough size to accomodate all students (just set studentCount to some appropriate number and not 1 like in the example below).
class Student{
public:
int studentID;
char studentName[20];
int currentEnrollment;
Student(){};
};
int main(){
int studentCount=1;
Student * students = new Student[studentCount];
int numStudents=0;
bool done=false;
char finished='N';
while (!done){
//Student *tempStudent = new Student();
//create a Student on the stack
Student tempStudent;
cout << "Please enter student id (4 digits only): ";
//No input checking is done here
cin >> tempStudent.studentID;
No input checking is done here
cout << "Please enter student name: ";
cin >> tempStudent.studentName;
students[numStudents] = tempStudent;
numStudents++;
cout << "Stop entering students: Y or N";
cin >> finished;
done = finished=='Y' or finished=='y' ? true : false;
if(numStudents==studentCount){
students = ReallocateStudents(students, studentCount, studentCount*2);
studentCount *= 2;
}
}//end while
//print the students info
for(int i=0;i<numStudents;i++){
Student st = students[i];
cout << st.studentID << " " << st.studentName << std::endl;
}
//deallocate the students array or if you place this in the main like you did, the program will exit immediately so there's no need to deallocate
return 0;
}
Student * ReallocateStudents(Student* st, int oldSize, int newSize){
Student * newStudents = new Student[newSize];
//copy the existing values from the old array to the new one
for(int i=0;i<oldSize;i++){
newStudents[i] = st[i];
}
delete [] st; //delete the old array
return newStudents;
}
UPDATE:
Since you don't want to do everthing in the main(), just create a free AddStudents function and do everything there. Alternatively, you can create a
static function inside the Student class. It makes no sense to create AddStudent as a member of Student because that would require you to use an instance of Student to add a new instance, which makes for poor design (not to mention technical issues etc).
int main(){
// some code here
Students * allStudents = AddStudents();
//print students
}//end main
Students * AddStudents(){
int studentCount=1;
Student * students = new Student[studentCount];
int numStudents=0;
bool done=false;
char finished='N';
while (!done){
//create a Student on the stack
Student tempStudent;
cout << "Please enter student id (4 digits only): ";
//No input checking is done here
cin >> tempStudent.studentID;
No input checking is done here
cout << "Please enter student name: ";
cin >> tempStudent.studentName;
students[numStudents] = tempStudent;
numStudents++;
cout << "Stop entering students: Y or N";
cin >> finished;
done = finished=='Y' or finished=='y' ? true : false;
if(numStudents==studentCount){
students = ReallocateStudents(students, studentCount,
studentCount*2);
studentCount *= 2;
}
}//end while
return students;
}
This is simple and easy to both understand and maintain so I suggest using this approach.
addStudent does not do anything with the Student object it belongs to. So there is no need to put it in the 'Student' class. (Or you could rather rewrite it so it does something with the student object it belongs to). And it currently does not "add" anything, so the name is confusing.
What is technically wrong with it depends on what you want it to do. Currently it initializes student objects expected to already exist and pointed to by an array, from a specific array index, to the end of the array. That could well be a useful function, if that is what you want it to do. But you then must call it correctly with an array of pointers that point to valid Student objects, which you currently do not.
Currently in main you have a loop that initializes pointers in an array. And each time you initialize a pointer, you call AddStudent(..). The problem is that 'AddStudent()' tries to initialize ALL the student pointed to by your array.
This has two major problems (In addition to all the other problems with your loop).
Each time you create a new student, all your existing students will be
initialized again with new input from std::cin. (So for n students, you will
try to do n*n initializations)
While the loop in main is running, not all pointers in your array points
to existing Student objects. This may result in important data being
overwritten, a program crash or something totally different and unexpected.
You should sit back and reevaluate how you want to do things. Trying to fix single bugs in your existing code, one after another, will just create more bugs.
Just a hint to get you started:
class Student
{
public:
int studentID;
char studentName[20];
int currentEnrollment;
Student();
void init_from_cin();
};
And in your class definition file:
void Student::init_from_cin()
{
cout << "Please enter student id (4 digits only): ";
cin >> studentID;
cout << "Please enter student name: ";
cin >> studentName;
}
If you create a new Student like this:
Student *new_student = new Student;
new_student->init_from_cin();
Then after calling init_from_cin(), the Student object pointed to by new_student should be initialized.
How to create and initialize multiple Student objects in a loop, is left as exercise for the reader. But when you do it, you should understand what your lower and upper bounds of your loop are supposed to be. And you should also understand why moving the upper bound further away while your loop is running is a bad idea.
And never forget that sane programming languages start array indexing with 0.
I am attempting to write the following:
1) Write the class definition for a class named Employee with name and salary as employee objects. The class contains two member functions: the constructor and a function that allows a program to assign values to the data members.
2) Add two member functions to the Employee class. One member function should allow any program using an employee object to view the contents of the salary data member. The other member function should allow the program to view the contents of the employee name data member.
3) Add another member function to the Employeeclass. The member function should calculate an employee objects new salary, based on a raise percentage provided by the program using the object. Before calculating the raise, the member function should verify that the raise percentage is greater than or equal to zero. If the raise percentage is less than zero, the member function should display an error message.
4) Write a main function that will create an array of employee objects, assign
values to the objects, display the names and current salaries for all objects,
ask user for the raise percentage and then calculate and display new salaries
for all objects.
I have attempted this with the following code:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class EMPLOYEE
{
public:
EMPLOYEE();//
EMPLOYEE(string name, int salary);//
public:
string name;//name to be input
int salary;//salary to be input
public:
int enter_values();
int output_values();
int NEW_SALARY( int percentage_raise);
};
//default constructor
EMPLOYEE::EMPLOYEE()
{
name = "";
salary = 0;
}
//constructor with name/salary variables
EMPLOYEE::EMPLOYEE(string NAME, int SALARY)
{
name= NAME;
salary= SALARY;
}
//name and salary to be input...
int EMPLOYEE::enter_values()
{ cout<<"Enter name and salary: ";
cin>> name;
cin>>salary;
}
//output
int EMPLOYEE::output_values()
{ cout<<"Name: "<<name<<endl;
cout<<"Salary: "<<salary<<endl;
}
//
int EMPLOYEE::NEW_SALARY(int percentage_raise)
{
EMPLOYEE updated_salary;
if ( percentage_raise >= 0){salary= salary *(percentage_raise/100);
}
else if(percentage_raise< 0)
{ cout<<"Error Message"<<endl;
}
return percentage_raise;
}
int main()
{
EMPLOYEE employees[100];
EMPLOYEE.NEW_SALARY();
int percent= 0;
int i;
for(i =0 ;i<100 ; i++)
{ employees[i]=EMPLOYEE();
employees[i].enter_values();
employees[i].name;
employees[i].salary;
employees[i].output_values();
cout<<"How much should the salary be raised by?"<<endl;
cin>>percent;
cout<<EMPLOYEE.name<<"'s new salary is "<<percentage_raise<<endl;
}
}
However, I cannot access the parts I need to store the information into the array in the main function, nor can I apply the percentage raise when the program prompts the user.
I'm pretty sure I have syntax errors which I am unaware of. I'm not asking for someone to do everything for me, but I would appreciate a steer in the right direction. I don't quite understand classes and how to call them into different parts of a program. Thank you for your time.
You have almost everything in good order.
Things to fix:
The line
if ( percentage_raise >= 0){salary= salary *(percentage_raise/100);
will set salary to zero unless percentage_raise is greater than 100. That's because the expression (percentage_raise/100) will be an integer division and will evaluate to zero, unless pecentage_raise is greater than 100.
You can fix it with:
if ( percentage_raise >= 0)
{
int raise = (salary*percentage_raise)/100;
salary += raise;
}
The line
EMPLOYEE.NEW_SALARY();
is going to produce a compiler error since there is no object named EMPLOYEE.
You can safely remove that line. It's not serving any purpose.
You are missing a call to set the percentage raise after you read the input. You need the line
employees[i].NEW_SALARY(percent);
immediately after you read percent.
The following line is incorrect.
cout<<EMPLOYEE.name<<"'s new salary is "<<percentage_raise<<endl;
since there is no object named EMPLOYEE. You can replace it with:
cout<<employees[i].name<<"'s new salary is "<<employees[i].salary<<endl;
class Employee
{
public:
Employee();
int salary;
};
Employee::Employee() { salary = 10; }
int main()
{
Employee joe;
std::cout << "Joe Salary: " << joe.salary << std::endl;
joe.salary = 15;
std::cout << "Joe New Salary: " << joe.salary << std::endl;
}
Usually, you will want your data members to be private and use an accessor method to provide the values of the data members which, again, should be private.
for a class assignment I have to write a class definition. Its called Employee class, something really basic for my first c++ class.
My problem is in the first forloop, when I try to adjust the salary based on the new percentage.
The variables inside the class don't change after that. I don't know what could be wrong anymore.
The code is:
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
int emplSalary;
string employeeName;
public:
Employee();
Employee(string name,int salary);
string getName();
int getSalary();
void newSalary(int percent);
void input();
void output();
};
Employee::Employee()
{
emplSalary=0;
employeeName="";
}
Employee::Employee(string name,int sal)
{
employeeName=name;
emplSalary =sal;
}
string Employee::getName()
{
return employeeName;
}
int Employee::getSalary()
{
return emplSalary;
}
void Employee::newSalary(int percent)
{
emplSalary= emplSalary *(1+(percent/100));
cout<<"I calculated"<<endl;
/*
if(percent < 0)
{
cout<<"Invalid Percentage";
cout<<"I calculated"<<endl;
}
else
{
emplSalary= emplSalary *(1+(percent/100));
cout<<"I calculated"<<endl;
}
*/
}
void Employee::input()
{
cout << "Enter Name: ";
cin>> employeeName;
cout<<"\n";
cout<<"Enter Salary: " ;
cin>>emplSalary;
cout<<"\n";
}
void Employee::output()
{
cout << "Name: " << employeeName <<" : "<< "Salary: " << emplSalary << endl;
cout<<"\n";
}
int main()
{
const int NUMBER_EMPLOYEE =1;
Employee employees[NUMBER_EMPLOYEE];
int percent;
cout<<"Welcome to Employee program. Enter Name and Salary when prompted."<<endl;
cout<<"\n";
cout<<"\n";
for (int i=0; i<NUMBER_EMPLOYEE; i++)
{
employees[i]=Employee();
employees[i].input();
cout<<"What percentage to raise the salary: ";
cin>>percent;
employees[i].newSalary(percent);
}
for (int i=0; i<NUMBER_EMPLOYEE; i++)
{
employees[i].output();
}
return EXIT_SUCCESS;
}
and the output is:
Welcome to Employee program. Enter Name and Salary when prompted.
Enter Name:
Enter Salary:
What percentage to raise the salary: I calculated
Name: : Salary: 0
The problem is in this line:
emplSalary= emplSalary *(1+(percent/100));
Because percent is an int, you are doing all integer math.
Suppose percent was 50.
The innermost part of your expression ends up being 50/100, which is 0 in integer math.
(You intended for the result to be 0.50).
To fix this, change the type of percent to be double.
Alternately, you can change 100 to be 100.0 (making it a double):
emplSalary= emplSalary *(1+(percent/100.0));
emplSalary= emplSalary *(1+(percent/100));
This line, if your percent is less than 99, percent/100 will be zero, that's why it has no affect to your result. You may want to use double type for your emplSalary and percent.
emplSalary= emplSalary *(1+(percent/100));
You're performing integer arithmetic there (emplSalaray and percent are both of type int). This means that percent / 100 will (unless percent is greater 99) always evaluate to 0. So the equation ends up being emplSalary = emplSalary * 1.
First, note that when the original salary is zero (which is what happens when you write employees[i]=Employee() and the default constructor sets the salary to 0), raises of any percentage will always remain zero,
Second, note that dividing an int by another int will perform integer arithmetic, so the quotient gets truncated. Raises between 0 and 100 percent will therefore be rounded to 0%. Divide by 100.0 instead of 100 to resolve that problem.