Posts by Luiz Augusto • 2,482 points
62 posts
-
0
votes1
answer60
viewsA: How to read keyboard data to an array in Java?
To the point: This occurs because, in the first iteration, when leaving the 2nd loop is ( for(;j<4;j++){ ) the variable j has value 4, and this value is not restarted, therefore in the second…
-
1
votes2
answers78
viewsQ: Access vector value by index
I’m practicing a little vector, when I come across this code, of an exercise: #include <stdio.h> main () { char ex3[5] = { 'z', 'k', 'w', 'x', 'v' }; int cont1; cont1 = 2; printf ("%c…
-
0
votes3
answers58
viewsA: The result comes out another
First, you are not printing the correct values as you are not passing the value correctly with the scanf() function, read this question:Why don’t you need the & in the scanf();? Later, in fact,…
-
1
votes1
answer994
viewsA: Help Portugol(ascending order)
You have made a small error of attention. See this excerpt from your code: se(i==1){ se(a>b e b>c) //Falta a chave de abertura aqui maior = a meio = b menor = c } You opened the keys to parole…
portugolanswered Luiz Augusto 2,482 -
0
votes2
answers169
viewsA: Read multiple values and average
The error is happening because you are passing -1 to the variable idade, therefore its average is passing the value 19 to the printf. To fix this place a structure if within your do..while; Your…
canswered Luiz Augusto 2,482 -
1
votes2
answers603
viewsA: While or Do While exercise using CHAR variable
As stated in the exercise there is no contraindication to use the structure switch-case, I took the liberty of improving your code, I believe with this structure it will be more readable. Do the…
canswered Luiz Augusto 2,482 -
1
votes3
answers54
viewsA: error in percentage?
Your if structure logic is incorrect, change all operators OR (||) for operator E(&&): For when you enter, for example, 700 reais for the wage variable it satisfies the condition of the…
canswered Luiz Augusto 2,482 -
1
votes1
answer147
viewsA: Resolution of Exercise
If every cigarette you smoke will lose 10 minutes of life, multiply the variable totalCig by 10, however, at this point, you will have the values in minute. Then to transform the values from minute…
portugol-studioanswered Luiz Augusto 2,482 -
1
votes3
answers503
viewsA: Sum of geometric progression terms
Since the formula for calculating the sum of the terms of an arithmetic progression is as follows:: Being: Sn = Sum of terms; a1 = First term; q = Reason; n = number of terms; This coded formula for…
-
4
votes1
answer126
viewsQ: echo output with % and %
When solving some exercises in Shell Script, I find this script: x="Este texto para teste." echo ${x% *} I confess that, when performing the table test, I could not solve it. When running this…
-
0
votes1
answer356
viewsA: Store random numbers in a variable in C
Instead of directly printing the function values rand(), assign values to variables d1 and d2. As Deitel quotes, in his book, when using the function srand() if we wish to randomize without the need…
canswered Luiz Augusto 2,482 -
0
votes1
answer1138
viewsA: C++ code error with getline(Cin,string)
When you enter the cout << "Insere tua idade: " he’s going to pass the \n ( enter) to the cin >> age; In turn it will be the first character read by getline(cin, nome); so this line is…
-
1
votes2
answers172
viewsA: How to verify if Valueerror occurred
According to the Python 3.x documentation this error Valueerror is caused Generated when an operation or function receives an argument that has the right type but an inadequate value. ( Translated…
-
0
votes1
answer51
viewsA: No dev c ++ giving an error: id returned 1exit status
According to this reply of the question: C Compile error: Id returned 1 Exit status, in English: Translated, via google Translate: I can only assume that the old instance of your program is still…
dev-c++answered Luiz Augusto 2,482 -
1
votes2
answers526
viewsA: C++ program for day of the week (with code example)
You always get into the case 1:, for its variable frac is returning 0 to the variable ds. This is happening because you didn’t make one casting of int for float within the function modf. Your…
-
2
votes2
answers529
viewsA: Change array values using for and if
From what I understand it’s this: Your array is so: array([-2.06133692, 0.3721 , -1.35233125, -2.05725375, 0.39800875, -2.0544975 , 0.66408308, -1.5466 , 0.66212308, -2.559165 ,]) But after the…
-
1
votes1
answer40
viewsA: Help here with a Ruby exercise
I believe you’re not getting out of the 2nd while by the double condition: while opt!=0 or opt!=2 See a problem similar to yours in English: Multiple conditions in a "While" Ruby loop One simple way…
rubyanswered Luiz Augusto 2,482 -
7
votes1
answer2019
viewsA: How do I get the size of a Java String?
Use the method length(), for this will return the size of a string in characters. Your code will stay: if(senhacriada.length() >= 8) { //! A solução está aqui ! System.out.println("Senha criada…
-
2
votes1
answer1169
viewsA: How to interrupt in Visualg?
Use the structure enquanto... faca Your code will look like this: var continuar: caracter inicio // Seção de Comandos, procedimento, funções, operadores, etc... continuar:="a" enquanto continuar…
-
5
votes2
answers127
viewsA: Total nodes of a perfect binary tree
Simple and fast: To discover the amount of nodes of a full binary tree, we use the formula: n = 2 ^ (h + 1) - 1 Being: n the amount we and, h the height of the tree. That is, in your example you…
answered Luiz Augusto 2,482 -
0
votes2
answers350
viewsA: Recursive algorithm for calculating arithmetic mean
You want the average of a list passed to a function recursively, so do this: l=[3,6,7] def media(l): if len(l) == 1: return l[0] else: return l[0] + media(l[1:]) media(l) print("A média da sua lista…
-
0
votes2
answers45
viewsA: Doubts in case of use
Depending on the UML - User Guide - BOOCH, RUMBAUCH, JACOBSON Actor: An actor represents a coherent set of roles that the users of use cases play when they interact with these cases of use.…
umlanswered Luiz Augusto 2,482 -
2
votes3
answers415
viewsA: Interfacing of vectors in python
I did not understand why to use a third vector, I believe it is to assign the values of vetor1 and vetor2, correct? If yes, a new vector is not required. To perform such intercalation we use the…
python-3.xanswered Luiz Augusto 2,482 -
2
votes2
answers288
viewsA: Make the program go back to the beginning
Is reply is valid, but you will not have the option to exit the program. Knowing this I implemented a stop option: opcao=0 while opcao !=1: tela=input('Com isso Coloque uma palavra ou frase para…
-
1
votes1
answer119
viewsA: Python counting by function, BASIC
Milton, as this reply pay attention to indentation! Are you putting the return at the same indentation level as if within the functions contaPositivo and contaNegativo, so it is returning erroneous…
pythonanswered Luiz Augusto 2,482 -
1
votes3
answers4032
viewsA: Python, even and odd number counting
You are misusing the for command: for lista in range(num): Note that using the loop for this way, you’re saying to scroll through the list using the last range num inserted by its input. Example:…
-
3
votes1
answer216
viewsA: Invalid syntax in Python, what’s wrong or missing?
Usually, when this error occurs, SyntaxError: invalid syntax in correct syntax you should look at previous line, indicating that maybe you forgot to close some bracket or parentheses. That’s exactly…
-
3
votes1
answer742
viewsA: What is the livelock?
Second, free translation, this reply: Taken from http://en.wikipedia.org/wiki/Deadlock : In simultaneous computing, a deadlock is a state in which each member of a group of actions is waiting for…
-
3
votes1
answer59
viewsA: Why is the result of my operation being printed printing 00 and not the actual result?
I believe your mistake was changing the types of variables and not changing the conversion specifiers of printf and of scanf See your code working properly: #include <stdio.h> #include…
canswered Luiz Augusto 2,482 -
6
votes1
answer135
viewsA: student register
You are making a small mistake. Note your line: opt= int(input("Escolha uma opção:")) You are converting the input to an entire numeric type (int) But is verifying the equality of values with…
pythonanswered Luiz Augusto 2,482 -
1
votes1
answer886
viewsA: Logical expression for (While or If) Create repetition until the user gets the answer right
Your optimized code will look like this: var RESPOSTA: CARACTERE CONDICAO: LOGICO inicio CONDICAO <- VERDADEIRO ENQUANTO CONDICAO = VERDADEIRO FACA…
-
2
votes3
answers562
viewsA: Math library
Although this reply be based on Microsoft . net it is well didactic, translated via google Translate: Follow these links to get the MSDN descriptions on: Math.Floor, rounded to negative infinity.…
-
1
votes2
answers138
viewsA: Read input data and write read lines to a file
Try this: arquivo = open('contas', 'w') def adicionar(): while True: print("O que quer adicionar?: ") a="\n".join(iter(input,"")) arquivo.write(a) if a == '': break adicionar() arquivo.close I…
pythonanswered Luiz Augusto 2,482 -
16
votes4
answers634
viewsA: What is the difference between i += 2 and i = i + 2?
As already commented, there will be no difference in the result. But we will do a simple debugging of your code: Using i += 2 from dis import dis code = ''' i=1 i+=2 ''' print(dis(code)) 2 0…
-
3
votes2
answers218
viewsQ: Destructor in C++
In solving some issues in C++, I came across the code: class MinhaClasse{ private: int a; public: MinhaClasse(int b){ a = b; ImprimeA(); }; ~MinhaClasse(){ IncrementaA(); ImprimeA(); }; void…
c++asked Luiz Augusto 2,482 -
2
votes2
answers211
viewsA: Why is it wrong when I try to assign a value to the variable within a conditional operator?
I checked your code with ternary operator and do not compile, but using the selection structure if/else the same compilation. #include <stdio.h> int max_of_four(int x, int z, int y, int w);…
-
0
votes2
answers374
viewsA: Errors in the program to determine triangle
I haven’t made any improvements to your code, but I’ll give you some tips to improve it The exit, unwanted, that you were found when the entrance was: ValorUm=10; ValorDois=5; ValorTres=3 Exit: NAO…
c++answered Luiz Augusto 2,482 -
9
votes2
answers214
viewsA: Inverting two variables without using a temporary
Try Multiple Assignment a=1 b=3 print("a=",a, "b=", b) a,b = b,a #Invertendo as variáveis sem uma variável auxiliar print("a=",a, "b=", b) Example above is very basic but functional for what you…
pythonanswered Luiz Augusto 2,482 -
0
votes2
answers418
viewsA: name ' ' is not defined
Lucas, you’re returning the error of name ' ' is not defined, because the variables were not defined in the function media() Note that you have defined the variables n1, n2, n3 and opcao in the body…
-
0
votes3
answers85
viewsA: Why is my Condition Structure assigning a value to a variable?
The "sum" adds the values of note[a] but I did not put value in "sum" for her to receive. Why does this happen? This happens, because you put the operation + 2 in the same line, as you did not start…
-
3
votes1
answer77
viewsA: C# - Collections - Enigma Exercise
Matheus, your understanding is correct, it’s an excerpt from a FILA implementation algorithm, as you may know, the concept tells us: They are data structures of type FIFO (first-in first-out), where…
-
1
votes1
answer36
viewsQ: Why am I printing in this order?
<?php function foo($var){ echo $var + 3; } $x = 1; echo "foo($x) =".foo($x); ?> I was watching some exercises in php,then I came across the code, thinking I was going to print foo(1) = 4, but…
phpasked Luiz Augusto 2,482 -
0
votes1
answer73
viewsQ: Why are the values of x and v[0] not equal? - C language
I’m reviewing some concepts on the site : Addresses and Pointers, until I find the following code: void func1 (int x) { x = 9 * x; } void func2 (int v[]) { v[0] = 9 * v[0]; } int main (void) { int…
-
2
votes4
answers115
viewsA: Algorithm execution error in pascal
Lacked a end at the end of the block case. The correct code will look like this: Program Crianca_Esperanca ; var D: integer; valor: real; Begin writeln('--------------------------------'); writeln('…
pascalanswered Luiz Augusto 2,482 -
0
votes1
answer450
viewsA: Visualg syntax error (English)
Note that you have declared the variable Result as character, so it will have to receive a 'value' character, note that Result <- Reprovado is different from Result <- "Reprovado" Observing:…
-
2
votes2
answers1896
viewsA: Visualg - Assign two variables on the same line
Depending on the English language manual, the read function allows the input of data, receiving the values typed by the user, assigning them to the declared variable along with the read function.…
-
4
votes2
answers1022
viewsA: Error: incompatible type for argument 1 of 'printf'
There are several errors in your code, I believe because you are a beginner! I recommend reading about printf and scanf functions Read this answer too Difference between %i and %d Your functional…
-
1
votes3
answers209
viewsQ: Can the "main()" method be overwritten or overwritten?
I read the answer What public Static void main(String[] args means)?, but I still have two doubts about the method main(): The method main() can be overloaded? The method main() may be…
-
4
votes1
answer278
viewsQ: Interpretation of logic operators in Java regarding short-circuit
I read that question Doubt about logical operators && e || in Java, but I follow with the doubt. Solving some exercises on Java I find such a statement: Operators & and | operate in the…
-
7
votes3
answers1494
viewsQ: Why is Python so current?
I noticed that the world’s leading sites (Google, Facebook, Youtube) still use Python. I found in several sites the advantages of using Python (simplicity, robustness...), but I still follow with…
pythonasked Luiz Augusto 2,482