trouble with a simple loop

Good evening! I have been having some trouble getting my code to compile. The task was to write a program that asked for a customers account number, balance, charges, credits, and credit limit. If the customer went over the program should display their balance, and tell them they exceeded. If they did not exceed their limit, the program would keep repeating until the sentinel in entered (-1). Thanks for anybody who chimes in with their help! I keep receiving the errors:

1>c:\users\matthew\documents\visual studio 2010\projects\98\98\1.cpp(18): error C2059: syntax error : '='
1>c:\users\matthew\documents\visual studio 2010\projects\98\98\1.cpp(19): error C2143: syntax error : missing ';' before '{'


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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	
	
	int accountNumber;
	double balance;
	double charges;
	double credits;
	double limit;
	double total; 
	double balanceremaining;
	
	cout << "Enter account number (-1 to end): " << endl;
	cin >> accountNumber;
	while (! = -1)
	{
		cout << "Enter begining balance:" << endl;
		cin >> balance;

		cout << "Enter total charges:" << endl;
		cin >> charges;

		cout << "Enter total credits:" << endl;
		cin >> credits;

		cout << "Enter credit limit:" << endl;
		cin >> limit;

		total = (balance + charges) - credits;

		if ( total < limit)
		cout << endl;
		else 
		cout << balanceremaining << endl;
		cout << "Credit Limit Exceeded" << endl;
	}

	return 0;
}

while (! = -1)

While what doesn't equal -1 ?
I noticed your name and am guessing you are a new programmer. the ! means NOT in C++ so !true means not true while !false means not false.

A while statement is testing for the condition of true. To test for the condition of false, you use the !

1
2
3
4
5
6
7
8
while(x<10)
{
   // Code
}
while(!(x < 10))
{
   // Code
}


Here is a simple example. The first while statement tests to see if x is less then 10 and runs. The second will test to see if x is less then 10 and then see if it is not true.

1
2
3
while(x != 10)
{
}


Here, this while statement will run as long as x is NOT EQUAL to 10.

Hopefully that helps you understand how ! is used in C++, Moschops was thinking the same thing I was, WHAT doesn't equal -1? you have nothing else in there and that is a problem. Reading your code, I figured out your code is suppsoe to say

 
while(accountNumber != -1)


But before I let you go, you need to know you will have a second problem. The code will compile but you will never be able to leave the loop once you enter it because accountNumber can only be changed before entering the while loop, not while in it. you should place the input in the while statement also.
Awesome! Thanks for the quick replies and she's running great. It's funny because I spent so much time looking at everything except that! Thank you again Moschops, and WilliamW1979.
Topic archived. No new replies allowed.