Monday, 4 March 2013

Activity 10: Nested FOR Loops


Activity 10: Nested FOR Loops
Write a program that uses nested For loops to display the times tables from 1 – 12 with a
new line for each times table.
·  Open a new single project with MFCAppWizard(exe) named LearnTables.
·  Declare a CString variable, line, in LearnTablesDoc.h.
·  Intialize in learnTablesDoc.cpp ( line =” ”;) and add the following code to
LearnTablesView.cpp.
void ClearnTablesView::OnDraw(CDC* pDC)
{
CLearnTablesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int i;
int j;
int y = 0;
CString convert = "";
for(i=0; i<12; i++)
{
pDoc->line = "";
for(j=0; j<12; j++)
{
convert.Format("%d", ((i+1)*(j+1)));
pDoc->line+= convert;
pDoc->line+=" ";
}
pDC->TextOut(0,y, pDoc->line);
y+=20;
}
}

No comments:

Post a Comment