Desk checking help c++ (Code provided)

Hi, im not too sure how to desk check but i've got a fair idea, though would like if you could use this code as a example to show me how to do it, ive got a question which ill show underneath, i've already done the flowchart and determined what this codes output will be. any help would be appreciated.

For the following C++ program

#include <iostream>
using namespace std;

int main()
{
int num = 0;
while (num <= 20)
{
num++;
cout << num << " ";
}

return 0;
}
determine the total number of items displayed, and the first and last numbers printed. Draw the flow chart for the C++ program, and then desk-check the program for the first 5 steps and the last 3.
use if statements and cout to print out only first, last first 5 , last 3 etc numbers etc.
use endl and * asteriks; to look like chart
Sorry thats abit confusing. Is that what desk checking is? is that what i'd write if it asked for desk check?
here is your checkdesk function:
call it at teh end of code of course.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void CheckDesk() {
	float num = 0, sum = 0, average = 0, total = 0, count = 0;
	cout << "number\tcount\ttotal\taverage\t\n";
	while (num < 5 || (num > 17 && num < 21)) {
		total += num;
		if (num == 4) {
			float temp_av = total / 4;
			cout << num++ << '\t' << ++count << '\t' << total << '\t' << temp_av << endl;
			num = 18;
			cout << "*************************************\nchecking last 3: \n"
				   << "***********************************\n";
			continue;
		}
		else cout << num++ << '\t' << ++count << '\t' << total << "\t-\n";
		if (num == 20) {
			average = total / 8;
			cout << num++ << '\t' << ++count << '\t' << total << '\t' << average  << "\t\n";
			continue;
		}
	}
}


with the rest may help u someone else.
Last edited on
Please don't give full solutions, especially without explaining how they work.
Topic archived. No new replies allowed.