Counter Controlled While Loop Error

Im having difficulties doing a counter controlled while loop and i get these errors and i just cant seem to figure it out.

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
/*****************************************************************************
M
Lab 5.1 A B
*****************************************************************************/
//Include header files
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>


using namespace std;


//Declare main
int main()
{
	//Declare variables
	int numberOfstudents;
	int counter = 0;
	string firstName, lastName;
	fstream USBout;

	//Prompt the user to enter the number of students
	cout << "Please enter the number of the students in this class  ";

	//Get the number of students
	cin >> numberOfstudents;

	//If number Of students is greater than 0
	if (numberOfstudents > 0);
	//Open the output file
	USBout("F:students.txt");

	//While the counter is less than or equal to number of students
	while (counter <= numberOfstudents);
	{
		//Prompt user for first and last name
		cout << "Please enter the First and Last Names of the students " << endl;

		//Get the first and last name
		cin >> firstName, lastName;

		//Store in output file
		USBout >> firstName >> lastName;

		//Update the counter
		counter++;
	}

	//Else display a message
	else cout << "No students in class" << endl;

	//Display a message to the user when the program is done
	cout << "Done" << endl;

	//End the main function
	return 0;
}

Errors:

Error 2 error C2064: term does not evaluate to a function taking 1 arguments 33 1

Error 3 error C2181: illegal else without matching if 52 1

4 IntelliSense: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type 33 2

5 IntelliSense: expected a statement 52 2

Warning 1 warning C4390: ';' : empty controlled statement found; is this the intent? 33 1

When i try to start without debugging a pop up says Unable to start program....... The system cannot find the file specified
Line 33 to USBout.open(//FileName)
http://www.cplusplus.com/reference/fstream/ifstream/open/

Line 52 else with no matching if.
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Never mind it works now. Thanks
Last edited on
Registered users can post here. Sign in or register to post.