Program to write out factors

I've been writing a program to get a number and publish factors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "Enter a number";				//ask for a number
	int a;						//declare a as integer
	cin >> a;					//get number
	int count=1;					//declare count and give it a value of 1
	do while (count <= a)				//open loop - while count is less or equal to a
	{
		if (a%count == 0)			//if the remainder of the number divided by count is 0 (it has found a factor)
		{
			if (count != 1)			//if count doesn't equal 1 (not the first factor)
			cout << " - " << count;		//separate them and write count
			else				//if not (if the first factor)
			cout << count;			//just write count
		}
	count +=1;					//add one to count
	}
	system("pause");
}


It's giving this error -

error C2061: syntax error : identifier 'system'

I'd appreciate if anyone helps
system is part of <cstdlib>, so you need to include that header if you want it.

But there are many reasons you shouldn't use system for this: http://www.cplusplus.com/forum/articles/11153/


Also, get rid of the 'do' on line 12. That's a while loop, not a do/while.
Thanks it's solved .. It's been a few days since I started C++, and been getting it mixed up with vb.

I actually didn't even have to use <cstdlib>, i don't know how but it got solved by itself after i fixed line 12.
Last edited on
You still should include cstdlib.
Topic archived. No new replies allowed.