Hello! I'm very new to c++ and am currently enrolled in an intro class. For my code, my output has an extra row in it and I've tried everything I can think of! I was hoping someone can tell me where my error is! Thank you guys in advanced.
This is what it should look like when enter the number 6 and char $:
What is the height of you parallelogram?
What character do you want to print?
$$$$$$$$$$$$
$ $
$ $
$ $
$ $
$$$$$$$$$$$$
Mine looks like:
What is the height of you parallelogram?
What character do you want to print?
$$$$$$$$$$$$$
$ $
$ $
$ $
$ $
$ $
$$$$$$$$$$$$$
problem lies in your loop. you used for (int var=0; var<=height; var++)
for both cases of x and y
if we look into detail of for loop, it actually runs until the condition becomes false.
lets assume that i inputted 3 and the loop will start from zero.
so x is initialized as 0, is 0 less than or equals to 3? true. run process, increment x.
x is now 1, is 1 less than or equals to 3? true. run process, increment x.
x is now 2, is 2 less than or equals 3? true. run process, increment x.
x is now 3, is 3 less than or equals 3? true. run process, increment x.
x is now 4, is 4 less than or equals 3? false. stop.
as you can see, you ran the command ONE extra time, because you have var<=height
solution is to either initialize x as 1, or use var<height