urgent help

hi every one i need your help in this problem



The college of Science has just bought a new photocopier. Any person using the photocopier must enter an identification code. You have been asked to do the following:
Write a program that determines whether identification codes typed by users of a photocopier are valid, and prints appropriate messages. If the identification code, which is a four-digit number, is correct your program computes the cost of copying according to the table below.
Your program should prompt the user for an identification code, read it and determine whether it is valid. An identification code is valid if its rightmost digit is correct. A correct digit is equal to the remainder of the sum of the other three digits divided by 7. For example, a valid code that gives a correct digit is 7011. However, 9999 is not a valid code.
7011 is a valid code because (7+0+1) % 7 is 1, which is equal to the rightmost digit of 7011.
But 9999 is not a valid code because (9+9+9) % 7 is 6, which is not equal to the rightmost digit of 9999.
Correct digits are assigned as follows:
Student: 1, 2. Teacher: 3, 4, 5. Secretary: 6
Number of pages 1 to 10 11 to 20 >20
Students 0.10 20% off 40% off
Teachers 0.30 30% off 40% off
Secretaries 0.20 25% off 40% off
Others 0.60 10% off 20% off

Write a program that read the monthly data at the end of each month from a file called science.in and generate the following data in an output file called science.out:
Each input lines contains a code followed by number of pages except the last lines it contains a negative number.
• Total number of copies
• Total cost
• Total number of copies made by students
• Total cost paid by students
• Total number of copies made by teachers
• Total cost paid by teachers
• Total number of copies made by secretaries
• Total cost paid by students


Put the code you need help with here.
what i have done so far is this
#include<iostream>
#include<cmath>
double checkprice(lastd,pages);
#include<fstream>

using namespace std;
int main()
{
double code, copies,price=0;

double d4,d3,d2,d1;


ifstream input ;
ofstream output;
input.open(science.in);
output.open(science.out)

input>>code

while(code>0)
{

check.code(code)


}













}
system("pause");
return 0 ;
}
check.code(code) ;
{
double copy,d4,d1,d2,d3,studentcopy=0,teachercopy=0,secreterycopy=0,othercopy=0;
d4=code%10;
d3=(code%100)/10;
d2=(code%1000)/100;
d1=code/1000;
if(d4==((d1+d2+d3)%7))
{
input>>copy;
switch(d4)
{
case 1:
case 2:
if (copy >=1&&copy<=10)
{
price=0.10 *copy;
cout<<"the cost is "<<price;

}
else if(copy >=11&&copy<=20)
{
price=(0.10*copy)-(0.10*copy*0.20);
cout<<"the cost is "<<price;}
else
{
price=(0.10 *copy)-(0.10*copy*0.40);
cout<<"the cost is "<<price;
}
studentcopy=studentcopy+copy

break ;
case 3:
case 4:
case 5:
if (copy >=1&&copy<=10)
{
price=0.30 *copy;
cout<<"the cost is "<<price;
}
else if(copy<=20)
{
price=(0.30 *copy)-(0.30 *copy*0.30);
cout<<"the cost is "<<price;
}
else
{
price=(0.30 *copy)-(0.30 *copy*0.40);
cout<<"the cost is "<<price<<endl;
}
break;
case 6:

if (copy >=1&&copy<=10)
{
price=0.20 *copy;
cout<<"the cost is "<<price;
}
else if(copy >=11&&copy<=20)
{
price=(0.20 *copy)-(copy*0.20*0.25);
cout<<"the cost is "<<price;
}
else
{
price=(0.20 *copy)-(copy*0.20*0.40);
cout<<"the cost is "<<price ;
}
break;
case 7:
case 8:
case 9:
if (copy >=1&&copy<=10)
{
price=0.60 *copy;
cout<<"the cost is "<<price;
}
else if(copy >=11&&copy<=20)
{
price=(0.60 *copy)-(copy*0.60*0.10);
cout<<"the cost is "<<price;
}
else
{
price=(0.60 *copy)-(0.60*copy*0.20);
cout<<"the cost is "<<price;
}
break;
}
}
else
{
cout<<"your code is not valid";
}

[/code]
please help by writing steps .I apericiate that.
double checkprice(lastd,pages);

First off, prototypes tell main what data types your functions will be dealing with. Not the variable itself. Change the variables to their respective data types (int, string, double, etc)

1
2
3
4
ifstream input ;
ofstream output;
input.open(science.in);
output.open(science.out)


When opening files, you must type the filename. Example: input.open("./filename.txt")

These are the things that jumped out. Fix these and see if any other errors come back.

thank you for replying but the main problem Im facing is dividing the the program into functions because its so complecated can you help me
It looks like you deleted the opening [code], so you have lost all formatting. I suggest you repost your code, as it is very hard to read in its current state.
Ask yourself what functions would make the problem easier to solve, or what functions are easy to write. I can think of two.

First, write a function that takes an ID code and returns which type of user (student, teacher, secretary) it is for. As a little trick, add "invalid" to the list of user types. For example:
1
2
3
4
5
6
enum User { Invalid, Student ,Teacher, Secretary }

enum User codeToUser(int code)
{
...
}


A second useful function would compute the charge for a copy run. This takes the number of pages and the user type:
double computeCharge(enum User u, unsigned pages);

Finally, once you have the user, number of pages and cost for a single run, you need to update the statistics that you're supposed to output, so maybe something like:
updateStatistics(enum User u, unsigned pages, double cost);

If you write these then putting them all together should be pretty easy.
dhayden has a good example there.

A good way to go about programs in the future is to write out what you need the program to do, and then write out the logical steps to get to that end goal. Functions are simply the pieces that come together to solve the problem.
Topic archived. No new replies allowed.