Hey guys I'm having a minor issue here, I'm having an issue with my sterling.cpp in the add functions sterling add(sterling s1, sterling s2) my question is how do I get it to realize when my shillings is > 20 to goto pounds and when my pence is > 12 to goto shillings? I have the driver.cpp to test out situations to make sure it all works. When it adds the numbers up it isn't just right. Any adivce?
//Driver.cpp my test
#include <iostream>
#include "sterling.h"
using namespace std;
int main(){
sterling s;
read(&s);
print(s);
sterling u = make_sterling(1, 20, 12);
print(u);
sterling a = add(s, u);
print(a);
return 0;
}
//sterling.cpp my functions
#include <iostream>
#include "sterling.h"
using namespace std;
sterling make_sterling(int po, int s, int pe){
sterling temp;
temp.pounds = po;
temp.shillings = s;
temp.pence = pe;
return temp;
}
sterling make_sterling(int pe){
sterling temp;
temp.pounds = pe / 240;
pe %= 240;
temp.shillings = pe / 20;
temp.pence = pe % 12;
return temp;
}
sterling add(sterling s1, sterling s2){
int i1 = s1.pounds * 240 + s1.shillings * 12 + s1.pence;
int i2 = s1.pounds * 240 + s1.shillings * 12 + s1.pence;
return make_sterling(i1 + i2);
}
void print(const sterling& a_sterling){
cout.fill('0');
cout << (char)156 << a_sterling.pounds << "." << a_sterling.shillings
<< "." << a_sterling.pence << endl;
cout.fill(' ');
}
void read(sterling* s){
cout <<"Please enter the pounds: ";
cin >> s->pounds;
cout <<"Please enter the shillings: ";
cin >> s->shillings;
cout <<"Please enter the pence: ";
cin >> s->pence;
}
//header sterling.h
struct sterling
{
int pounds;
int shillings;
int pence;
};
sterling make_sterling(int po, int s, int pe);
sterling make_sterling(int pe);
sterling add(sterling s1, sterling s2);
void print(const sterling& a_sterling);
void read(sterling* s);