I am doing a multi file program and I got it to work correctly in a single file but when I split it up it isn't working properly. I keep getting errors when i compile. Can anyone help me figure out where my mistake is thanks. This is what I have so far.
In a vendlib.h file I have
// include file for project 3
//converts input to product_price
int product_price(i nt);
//converts dollars to cents
int dollars_cents(i nt);
// coverts deposit to one int.
int total_deposit(i nt);
//converts deposit to the amount of change in cents
int total_cents(int );
//converts change to quarters
int quarters(int);
//converts change left to dimes
int dimes(int);
//converts change left to pennies
int pennies(int);
then my main.cpp file looks like this
#include<iostre am>
#include "vendlib.h"
using namespace std;
int main()
{
char another;
cout << "Welcome to online vendiing machine." << endl;
cout << "Product list: 1. M&M($0.65) 2. Chips ($1.16) 3. Pepermint gum ($0.28)."<< endl;
cout << "would you like to make a purchase?" << endl;
cin >> another;
while (another =='y')
{
cout << "Enter amount of money deposited in dollars first then cents:";
int dollars,cents;
cin >> dollars;
cin >> cents;
int x,y,z;
int product_number;
cout << "Enter Product number.";
cin >> product_number;
x = product_price(p roduct_number);
y = dollars_cents(d ollars);
z = total_cents(xy) ;
cout << total_cents << endl;
int count=1;
while (count <= 3)
{
int C1,C2,C3,l_c,a, b,c;
int total;
total = total_cents;
a = (total/25);
if (a > 0)
C1=(a*25);
if (a == 0)
C1= 0;
l_c=(total_cent s-C1);
count ++;
b = (l_c/10);
if (b>0)
C2=(b*10);
if (b == 0)
C2=0;
l_c=(l_c - C2);
count ++;
c = (l_c/1);
if (c > 0)
C3 = c;
if (c == 0)
C3 = 0;
count ++;
cout << "Your change is";
cout << a << "quarters " <<" " << b << "dimes " <<" " <<"and "<< c <<"pennies" << endl;
}
cout << "would you like another purchase. (y/n)" << endl;
cin >> another;
}
return 0;
}
then I have a vendlib.cpp that has the def's for my functions
/definitions file for project3
//
//
#include "vendlib.h"
//assigns the value of puchase to selection.
int product_price(i nt)
{
a = (product_number == 1)
product_price = 65;
a = (product_number == 2)
product_price = 116;
a = (product_number == 3)
product_price = 28;
return a;
}
// takes input from user in dollars and converts it to cents.
int dollars_cents(i nt)
{
int a = (dollars * 100);
return a;
}
//takes both converted dollars and cents and puts them in one variable
int total_deposit(i nt)
{
a = dollars_cents;
b = cents;
c = (a + b);
return c;
}
// total_cents is the the amount of money left after there purchase.
int total_cents(int ,int)
{
tc =(total_deposit - product_price);
return tc;
return b;
}
//quarters will take the amount after purchase and give how many quarters
//are given back.
int quarters(int)
{
int a = (total_cents/25);
return a;
}
//dimes wil take the amount left after quarters and give how many dimes
//are given back.
int dimes(int)
{
int a = (l_c/10);
return a;
}
//penny will take anything that is left after quarters and dimes, and
//assign it to pennies.
int pennies(int)
{
int a = l_c
return a;
}
Im not sure if the problem is in my definitions or the main. I got it to work in a single file but this is the first time I have had to split up a program.
In a vendlib.h file I have
// include file for project 3
//converts input to product_price
int product_price(i nt);
//converts dollars to cents
int dollars_cents(i nt);
// coverts deposit to one int.
int total_deposit(i nt);
//converts deposit to the amount of change in cents
int total_cents(int );
//converts change to quarters
int quarters(int);
//converts change left to dimes
int dimes(int);
//converts change left to pennies
int pennies(int);
then my main.cpp file looks like this
#include<iostre am>
#include "vendlib.h"
using namespace std;
int main()
{
char another;
cout << "Welcome to online vendiing machine." << endl;
cout << "Product list: 1. M&M($0.65) 2. Chips ($1.16) 3. Pepermint gum ($0.28)."<< endl;
cout << "would you like to make a purchase?" << endl;
cin >> another;
while (another =='y')
{
cout << "Enter amount of money deposited in dollars first then cents:";
int dollars,cents;
cin >> dollars;
cin >> cents;
int x,y,z;
int product_number;
cout << "Enter Product number.";
cin >> product_number;
x = product_price(p roduct_number);
y = dollars_cents(d ollars);
z = total_cents(xy) ;
cout << total_cents << endl;
int count=1;
while (count <= 3)
{
int C1,C2,C3,l_c,a, b,c;
int total;
total = total_cents;
a = (total/25);
if (a > 0)
C1=(a*25);
if (a == 0)
C1= 0;
l_c=(total_cent s-C1);
count ++;
b = (l_c/10);
if (b>0)
C2=(b*10);
if (b == 0)
C2=0;
l_c=(l_c - C2);
count ++;
c = (l_c/1);
if (c > 0)
C3 = c;
if (c == 0)
C3 = 0;
count ++;
cout << "Your change is";
cout << a << "quarters " <<" " << b << "dimes " <<" " <<"and "<< c <<"pennies" << endl;
}
cout << "would you like another purchase. (y/n)" << endl;
cin >> another;
}
return 0;
}
then I have a vendlib.cpp that has the def's for my functions
/definitions file for project3
//
//
#include "vendlib.h"
//assigns the value of puchase to selection.
int product_price(i nt)
{
a = (product_number == 1)
product_price = 65;
a = (product_number == 2)
product_price = 116;
a = (product_number == 3)
product_price = 28;
return a;
}
// takes input from user in dollars and converts it to cents.
int dollars_cents(i nt)
{
int a = (dollars * 100);
return a;
}
//takes both converted dollars and cents and puts them in one variable
int total_deposit(i nt)
{
a = dollars_cents;
b = cents;
c = (a + b);
return c;
}
// total_cents is the the amount of money left after there purchase.
int total_cents(int ,int)
{
tc =(total_deposit - product_price);
return tc;
return b;
}
//quarters will take the amount after purchase and give how many quarters
//are given back.
int quarters(int)
{
int a = (total_cents/25);
return a;
}
//dimes wil take the amount left after quarters and give how many dimes
//are given back.
int dimes(int)
{
int a = (l_c/10);
return a;
}
//penny will take anything that is left after quarters and dimes, and
//assign it to pennies.
int pennies(int)
{
int a = l_c
return a;
}
Im not sure if the problem is in my definitions or the main. I got it to work in a single file but this is the first time I have had to split up a program.
Comment