Oct 23, 2015 at 9:30pm UTC
I need to make a user defined size ( assume odd number) rectangle with a cross in the middle to be outputted. RIght now it just spams the screen with
. . . . .
. . . . .
. . . . .
and carries on doing this.
What i want is
. . * . .
. . * . .
*****
. . * . .
. . * . .
#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int numRows;
int numCols;
cout << "Please enter the Number of Rows \n";
cin >> numRows;
cout << "Please enter the number of Columms \n";
cin >> numCols;
for (int r = 0; r < numRows; r++)
{
for (int c = 0; c < numCols; c++)
{
//output row and colum positions
if (r = (numRows / 2) + 0.5 || (numCols / 2) +0.5)
{
cout << ". ";
}
else
{
cout << "* ";
}
}
cout << endl;
}
getchar();
return (0);
}
Last edited on Oct 23, 2015 at 10:01pm UTC
Oct 23, 2015 at 9:37pm UTC
I'm a beginner too, however you're missing your {} on your if and else statements. Also you should only have one else statement and all the rest (after the first if) should 'else if' statements. Not sure if that is your problem but it's definitely something that needs fixed.
Oct 23, 2015 at 9:46pm UTC
Doh. Thanks :) Ill see if i can get it working now
Oct 23, 2015 at 9:55pm UTC
Hmm still having problems, ive adjusted the code to fix the double else and missing the {} but it still just keeps on spamming down the screen
Oct 23, 2015 at 10:00pm UTC
=
is assignment
==
is comparison
Oct 23, 2015 at 10:28pm UTC
Thank You !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
for (int r = 0; r < numRows; r++)
{
for (int c = 0; c < numCols; c++)
{
//output row and colum positions
if (r == numRows / 2 || c == numCols /2)
{
cout << ". " ;
}
else
{
cout << "@ " ;
}
}
cout << endl;
Last edited on Oct 23, 2015 at 10:37pm UTC