Program just exit

Hi Ya,

Can someone assist please?

if i do ctrl+F5 program says "press any key to exit" after the 'while' loop

if i do normal run (F5) it doesn't draw the rectangles after i enter 'Y' or 'N', program just stays idle-
I was expecting the Dten object to call the Drawrect class and draw? any ideas please?

// *.h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
using namespace std;
class Dten
{
public:
Dten(short x, short y);
~Dten(){};

void Drawrect( short bx, short by, bool def=0) const;

private:
short ix;
short iy;
};

Dten::Dten(short x, short y):
ix(x), iy(y)
{}

void Dten::Drawrect(short bx, short by, bool def) const
{
short temp1=0;
short temp2=0;

if (def==1)
{
short temp1=ix;
short temp2=iy;
}

else
{
short temp1=bx;
short temp2=by;
}
for (short i=0; i<temp1; i++)
{
 for(short j=0; j<temp2; j++)
	{
	cout<<"+";
	}
	cout<<"\n";
}

}

[code]

// *.cpp file

[code]
#include <iostream>
#include <cctype>
#include "mQuizDay10.h"

using namespace std;
int main()
{
short ax, ay;
char ans;
Dten Drawer(5,5);

cout<<"Draw a rectangle (Y/N)?\n";
cin>>ans;

while ((toupper(ans)!='Y')&&(toupper(ans)!='N'))
{
cout<<"Invalid character, please Type Y for Yes and N for No\n";
cin>>ans;
}

if(toupper(ans)=='Y')
{
Drawer.Drawrect(10,10,0);
}

if(toupper(ans)=='N')
{
Drawer.Drawrect(5,5,1);
}
cin.ignore();
return 0;

}

In lines 27,28 and 33,34 you declare new local variables temp1 and temp2, which hide the corresponding temp1 and temp2 from outer scope. The changes are then made to these local variables, while the outer-scope ones stay unchanged (zeroes), thus nothing is drawn. You should remove the short in lines 27,28,33,34.

Some info on scopes and hiding can be found here:
http://msdn.microsoft.com/en-us/library/b7kfh662.aspx
->KRAkatau,
Many many thanks, I can't believe i have to travel all the way to my Mate's to help me only to realise I could have just come on this site from anyway!!!

So sad this site haven't got photos to names- but if you are opposite sex then triple kiss xxx for your help.

It works now, albeit, it exits after drawing the rectangles, but this is something I can resolve if I dig deeper into my memory banks anyway.

Cheerio!
Topic archived. No new replies allowed.