Variable DivisionCount is not an integer datatype?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am using Cody Coursework for this code, but I keep getting an error that states 'Variable DivisionCount should be integer datatype. I'm not sure what is wrong with my code.
Question:: 'The test suite assigns a random number to the variable Number. Write a script that uses a while loop to repeatedly divide this number by 7 until the value remaining is less than 1. Assign the result to the variable WhatsLeft. Keep track of the number of divisions required and assign to the integer variable DivisionCount.'
What I have::
count = 0
while Number>1
Number = Number/7
count = count + 1
end
WhatsLeft = Number
DivisionCount = count
0 commentaires
Réponses (1)
dpb
le 25 Fév 2017
All variables are by default type double in Matlab unless you make them something else; simple assignment won't do it, even if the value is integer-valued.
Don't know why it needs to be, other than the rules of engagement say so, but
DivisionCount=int32(count);
will do it. You could, of course initialize it and use it instead of the temporary count.
Also, note that the requirement is for result to be <1; your loop will stop if initial value is a multiple of 7 at 1.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!