Skip to content

Commit

Permalink
fixed wrong error judgement
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawrence-Link committed Aug 17, 2020
1 parent 0be0e2b commit be6bb9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions geometric-ser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[A geometric series sub element adder]
START STOP
↓ ↓
[A B C D E F G] elements
↑ ↑ ↑ ↑ ↑ ↑ ↑
------------- PUBL_RATIO
Expand All @@ -21,7 +21,6 @@ unsigned long STOP_AT;
unsigned long PUBL_RATIO;

void calc_fail();
void multipleByC(long & _input);

int main()
{
Expand All @@ -40,28 +39,28 @@ int main()
static unsigned long proc_num = START_AT;
static long answer_final = START_AT;
static bool calFailedFlag = false;

do
{
proc_num *= PUBL_RATIO;
answer_final += proc_num;
cout << answer_final << endl;

if (answer_final < 0){ // NOT fine
//cout << answer_final << endl;
cout << proc_num << endl;
if (answer_final < 0 || proc_num > STOP_AT){ // NOT fine
calc_fail();
calFailedFlag = true;
break;
}

} while (proc_num != STOP_AT);

} while (proc_num != STOP_AT && proc_num < STOP_AT);

if (!calFailedFlag && cin.good())
if (!calFailedFlag && cin.good() && proc_num == STOP_AT)
{
cout << "This is the final answer." << endl;
cout << answer_final << endl;
}
}

else
{
cerr << "Input valid. Check if anything goes wrong, maybe you just entered characters?";
Expand Down
Binary file modified geometric-ser.exe
Binary file not shown.

0 comments on commit be6bb9a

Please sign in to comment.