The code has a lot of errors, and although it will be able to deliver the work it does not seem that you will be learning to solve what comes up and this will bring you problems in the future. A lot of errors occur by mixing C with C++. Even when written correctly you should not do this. As it was said that it should be C++ this is how I will demonstrate.
#include <iostream>
using namespace std;
int main(void) {
int totalempresa = 0;
while (1) {
int valordomes1, valordomes2, valordomes3;
cout << "valor do mes 1:";
cin >> valordomes1;
if (valordomes1 == 0) break;
cout << endl << "valor do mes 2:";
cin >> valordomes2;
cout << endl << "valor do mes 3:";
cin >> valordomes3;
int totalfilia = valordomes1 + valordomes2 + valordomes3;
cout << endl << "Valor total da filial: " << totalfilia << endl;
cout << "------------------------------------" << endl;
totalempresa += totalfilia;
cout << "Total do restaurante: " << totalempresa << endl;
cout << "se nao deseja calcular o proximo valor de vendas de outra filial digite o numero zero" << endl;
}
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
All things are printf
must be cout
, is correct for C++. And where it is scanf
must use cin
. And note well the operators of stream <<
used in the cout
since you take data and send it to the exit, the cout
, and >>
where you send the entrance that comes from cin
for a variable. So it has a logic of when to use each and where.
Beyond that I put endl
at the exits to decorate better and skip lines where relevant. Each different die should be a stream different. In some cases using a ` n within the text itself is well acceptable and correct.
If the exit criterion is to type zero in the first input then the loop logic is wrong. It should have an infinite loop and right after someone type the number of the first month should check if it is 0 and if it is leaving the loop.
Only one variable should be outside the loop that is the one that calculates the total of the restaurants, after all this variable can not be zeroed in each passage of the loop, the others can and even one should be zeroed to work, and anyway declaring a variable closer to where it is used is the most suitable, so I passed all the other variables that remained (eliminated one) into the loop, and doing the initialization. If you don’t initialize, you can pick up garbage and there’s a lot of things wrong.
I eliminated the unnecessary parentheses, but mostly eliminated the :=
which is a non-existent operator in C++ (or C).
I did sum up the affiliate in the company which is something that seems to me that was what I wanted. Without making the sum has a logic error.
Another mistake is that some places that are as text were the names of variables, I removed the quotation marks. How he had case that did right does not seem ignorance but lack of care.
I didn’t change the variable names but I should adopt a style pattern and give full meaningful names, not letters, it just has disadvantages to do this. Then a valorDoMes1
would be better, just as totalFilial
. Standardizing the style holds for other things that I realized there wasn’t much worry. Had some variables with wrong name and so the code would not compile.
Programming is understanding what each character of the code does, even the blank space, not playing a lot of text anyway and hoping it works. First understand what is happening in each character and next you can do it knowing what it is.
Your code has such a large number of syntax errors, I ask: What led you to write it this way?
– Victor Stafusa
People just left portugol, have kkk patience.. Giving this error: [Error] invalid operands of types 'int(const char*, ...)' and 'const char [12]' to Binary 'Operator>>'
– Gisele muniz
And why are you trying to use things C decided to program in C++? The first thing you need to decide is what language you’re going to use, that might be the reason for the initial confusion.
– Maniero