The trying to write a program that asks for the number of lines the
user wants to output then the display should scroll down that many
lines with line number starting where col=row. I want it to look like this
(Disregard the "-," I couldn't figure out how to display it without them)
ex: input value: 5
----5
---4
--3
-2
1
However, the code I have written gives an output that looks like this:
1
-2
--3
---4
----5
What would I have to change in my code to produce the first diagonal line? Thanks for your help!
//System Libraries
#include <iostream>
usingnamespace std;
//Global Constants
//Function Prototypes
//Execution Starts Here
int main(int argc, char** argv) {
//Declare Variables
int n;
//Input number of lines
cout<<"Enter how many lines would you like to output?\n";
cin>>n;
//Output lines and spaces to create diagonal
for(int lines=1; lines<=n; lines++){
for(int space=2; space<=lines; space++){
cout<<" ";
}
cout<<lines;
cout<<"\n";
}
return 0;
}