@dev7060 - thank you for such a quick reply
Unfortunately, Stoney hasn't returned since the post was made - for those that follow, it's really rude to say something is urgent with a deadline, in this case 2022-05-28, (as I write this it is 2022-05-28-19H10-UTC) and then not return.
For those that follow:
+First problem is on line 5
days<=17;
, as dev7060 pointed out, this is a conditional comparison. One can only guess that OP intended for the loop that follows to have 17 itterations; therefore, the code is corrected to
days=17;
(My personal preference is to never use "day" or "days" as a variable name in that these are often reserved keywords - IMNSHO one should use something like "myDay" or "varDay" etc... i tend to use things like "zDay" or "z_Day"
+
7 23 C:\Documents and Settings\Administrator\My Documents\Untitled1.cpp [Error] expected ')' before ';' token
(the remaining errors are related to this one) indicates that there is a syntax error on line 7 position 23
for(int i;i<=days;i++;)
. One can only guess that this was a typo as the code could be
for(int i;i<=days;i++);
infact that trailing semicolin could be omitted (at least in VS2019IDE)
(yes, there are other issues here)!
+Correcting this to
for(int i;i<=days;i++)
creates an infinite loop in that the conditional will always be true in that the variable was set to a null value which will not (in/de)-crement. So let's correct that issue with
for (int i = 1; i <= days; i++)
+ So now the code will compile in the debugger and run... wait for it... ; HOWEVER, there are a few improvements.
As written this code is user and compiler unfriendly! When I took my CompSci courses (ages ago, dinosaurs walked the Earth!) we were graded on three points: does the code meet the project rubric, is the code compiler friendly (does not include things that are not needed); is the user feed-back human friendly (could someone execute the program and know what to do during interaction)
> Lets take care of the compiler unfriendly
#include <stdc++.h>
includes a lot of stuff that simply isn't needed in this code. All that is needed is
#include <iostream>
As for the user unfriendly - break that huge
cin
appart and instert a few prompts, some user message, format the output a bit and you get something like:
- #include <iostream>
-
using namespace std;
-
int z_days, z_gold, z_silver, z_copper, z_all, z_sum, z_sumg, z_sums, z_sumc;
-
//
-
int main()
-
{
-
z_days = 17;
-
cout << "How Much: gold, silver, copper (press enter after each entry)" << endl;
-
for (int i = 1; i <= z_days; i++) {
-
cout << "Day " << i << " of " << z_days << endl;
-
cout << "Gold? ";
-
cin >> z_gold;
-
cout << "Silver? ";
-
cin >> z_silver;
-
cout << "Copper ";
-
cin >> z_copper;
-
cout << "---------------- " << endl;
-
z_sumg = z_gold + z_sumg;
-
z_sums = z_silver + z_sums;
-
z_sumc = z_copper + z_sumc;
-
z_sum = z_sumg + z_sums + z_sumc;
-
}
-
cout << "---------------- " << endl << "Days:" << z_days << "; SumG:" << z_sumg << "; SumS:" << z_sums << "; SumC:" << z_sumc << "; Total:" << z_sum << endl;
-
return 0;
-
}
with an output (for 3 days...):
- How Much: gold, silver, copper (press enter after each entry)
-
Day 1 of 3
-
Gold? 1
-
Silver? 2
-
Copper 3
-
----------------
-
Day 2 of 3
-
Gold? 4
-
Silver? 5
-
Copper 6
-
----------------
-
Day 3 of 3
-
Gold? 7
-
Silver? 8
-
Copper 9
-
----------------
-
----------------
-
Days:3; SumG:12; SumS:15; SumC:18; Total:45