#include <iostream>
#include <fstream>
using namespace std;
int a,b,c;
bool results[21];
int left = 0;
void pour(int depth, int last, int am,int bm, int cm){
if(depth >= 15) return;
if(am == 0) results[cm] = true;
if(am > 0){
if(bm < b && last != 3){
int left = pourTwo(a,am,b,bm);
pour(depth+1,1,left,am+bm-left,cm);
}
if(cm < c && last != 5){
int left = pourTwo(a,am,c,cm);
pour(depth+1,2,left,bm,am+cm-left);
}
}
if(bm > 0){
if(am < a && last != 1){
int left = pourTwo(b,bm,a,am);
pour(depth+1,3,am+bm-left,left,cm);
}
if(cm < c && last != 6){
int left = pourTwo(b,bm,c,cm);
pour(depth+1,4,am,left,bm+cm-left);
}
}
if(cm > 0){
if(am < a && last != 2){
int left = pourTwo(c,cm,a,am);
pour(depth+1,5,am+cm-left,bm,left);
}
if(bm < b && last != 4){
int left = pourTwo(c,cm,b,bm);
pour(depth+1,6,am,bm+cm-left,left);
}
}
}
int main()
{
ifstream fin("milk3.in");
fin >> a >> b >> c;
fin.close();
ofstream fout("milk3.out");
bool anyprinted = false;
for(int i = 0; i < 21;i++){
if(results[i] == 1){
if(anyprinted) fout << ' ';
else anyprinted = true;
fout << i;
}
}
fout << endl;
fout.close();
return 0;
}
The relevant piece being:
int left = 0;
int pourTwo(int capOne,int filledOne,int capTwo,int filledTwo){//returns remaining in source bucket
return max(0,filledOne - (capTwo - filledTwo));
}
void pour(int depth, int last, int am,int bm, int cm){
if(depth >= 15) return;
if(am == 0) results[cm] = true;
if(am > 0){
if(bm < b && last != 3){
int left = pourTwo(a,am,b,bm);
pour(depth+1,1,left,am+bm-left,cm);
}
...
The problem is, where I've highlighted "int", I'm forced to redeclare "left", which I've already declared as a global variable. If I try to just set the value without declaring it as an int, I get "error: `left' undeclared (first use this function)". How stupid am I being here, and what's going on? Thanks for the help.

New Topic/Question
Reply



MultiQuote







|