Okay, so I’m trying to make a very simple program in ruby and I keep running into errors. I don’t want answers directly, but I would like guidance because it’s for school and I’m not a fan of cheating. I am writing a simple program where the user puts in the length and width of their iPhone screen and then the program will multiply the area by 326. 326 is the pixels-per-inch (PPI) of the resolution, and then that value multiplied by (length x width) would give the total pixels on the screen.
What I have so far:
l = gets.to_i
w = gets.to_i
print "What is the length of the screen?"
#(dont know how to get them to enter it)
print "What is the width?"
#(same as line before dont know how to get them to enter it)
result = 326(l*w)
Thats all I have and would appreciate any help, just don’t give me the entire program, please!
You should print the prompt message BEFORE calling
getsso the prompt message is on the screen while they are typing.This line is incorrect:
Unlike in math, in Ruby you can’t just put two numbers next to each other and expect them to be multiplied. You have to use the
*(asterisk) to multiply. So you will need a total of two asterisks on that line.You should use
putsat the end to print out the result.