Simple nested loop question

Hello everyone, I am new to the forum and this is my first topic. I am learning C++ and the task I am trying to complete asks me to do the following:-

"A program that prompts the user for an integer.
When they enter a positive integer eg 7, it then displays the 7 times table (up to 10 times
7), then prompts for a new integer.
It repeatedly displays times tables (as specified by user input) until they enter 0 instead of
a positive integer.
So it has NESTED loops:
Loop until user enters 0
Prompt and get user number N
Display heading “Times table for N” (where N is the number they enter)
Loop over range of times table (1 till 10)
Display index and index * N"

The problem is that the console launches blank and I'm not sure what I have done wrong. I am sure it is something a seasoned coder could spot in a matter of seconds.


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
#include "stdafx.h"
#include "math.h"
#include <Windows.h>
//the following 2 lines are necessary to include the library for displaying to a console window
#include <iostream>
using namespace std;

// Declared Variables
int counter=0;
int usernumber=1;
int answer=0;

// Main program body
int main()
{
	while (usernumber>0);
	{
		//user number prompt
		cout<<"Please enter an interger (e.g. 9): "<<endl;
		cout<<"To exit the program, enter '0'."<<endl;
		cin>>usernumber;

		//table header
		cout<<"Times table for "<<usernumber<<endl;
		for (counter; counter<11; counter++)
		{
			cout<<counter<<"\t";
			answer=counter*usernumber;
			cout<<answer<<endl;
		}
	}

	return 0;
}


Thank you very much in advance =)
Get rid of the semicolon on line 16.
Oh silly me =P

Thank you very much!
Last edited on
Topic archived. No new replies allowed.