Hi! I am new to arduino and C++ programming and our instructor wants us to make the following programs. I've been researching about syntax and codes but still I can't program properly. I only learned how to input an int number and display it as is by using the atoi code.
So here's the programs I have to make and are due next week. Take note that input and output must be a number, not a string or char, preferably an int or long. I can only tell how the program should be but I do not know how to code it. Please help..Thanks!
1.A program that will accept a byte from the keyboard. The program determines if the byte is even or an odd. If it is even, it will compute and display the square of that byte. if it is odd, it will compute and display the cube of that byte.
ex: if i input 2, it will display " 2 is even and the square is: (squareValue)"
if i input 3, it will display "3 is even and the cube is: (cubeValue)"
2.A program that will accept 4 bytes from the keyboard. The program determines which byte is the smallest, the biggest and computes and display them as well as their average.
ex: if I input number '1234' all at once, the program will read each byte from that int/long which is 1,2,3, and 4 individually and compares to each other to know which byte is the smallest and which byte is the biggest and will display as:
The smallest byte is: 1
The biggest byte is: 4
The program will then computes the average
averageVal=(1+2+3+4)/no.of bytes //no. of bytes will be 4, since the input number "1234" is 4 bytes
and display it as:
The average is: (averageVal)
3.A program that will accept 5 signed bytes (+ or - byte). The program will display the count of positive bytes and the count of negative bytes.
ex: if i input 4,-5,1,-3,2 individually,which is a number after the other.
The byte is: 4 //after i input 4, it will be displayed like this. Next input will be 5 and will be displayed also like this.This will continue
The byte is: -5 this will continue till there will be an input of 5 bytes.
The byte is: 1
The byte is: -3
The byte is: 2
The count of positive bytes is: 3 //since 4,1 and 2 are positive
The count of negative bytes is: 2 //since -5 and -3 are negative
4.A program that will accept a byte from the keyboard. The program count the number of 1's on that accepted byte and display the at the output.
Ex: if i input numbers "2311451" all at once, the program will read each byte from that int/long individually and computes how many 1's are there in that number.
The count of 1's is: 3 //since there are 3 1's in the '2311451' number.