error expected 'while' before numeric constant.


// calc5_cpp //

#include <string>
#include <conio.h>
#include <iostream>

main()
{
float cr,dr;
float Bank = 3500.00
char ch,q;
int input;
char again;
do
{
cout<<" Enter amount to credit or debit the bank ";
cout<<" Enter an option 1 or 2 " <<endl;
cout<<endl;
cin>>input;

switch(input)
{
case 1:{
cout<<endl;
cout<<" Enter amount to credit the Bank."<<endl;
cin>> cr;
Bank += cr;
cout<<" Bank is now "<< Bank <<endl;
cr = 0;
break;}
case 2:{
cout<<" Enter amount to debit the Bank. "<<endl;
cin>> dr;
Bank -= dr;
dr = 0;
break;}
cout<< " Bank is now " << Bank <<endl;
cout<< " Would you like to restart( y or n)";
cin>> again;
while(again == 'y' || again == 'Y')
{
cout<<"Your ending balance is:" << Bank <<endl;
}
}
}
return 0;
}
The format of wo-while statement is the following


do statement while( consdition );

If you use a compound statement then the format is

do { statements; } while ( condition );

In your code there is no closing brace before while though you are using a compound statement.
Thank you vlad for your reply to my problem.
Would it be possible for you to show me a better way
to write this program. Again thanks vlad.

The prog.compiles ok but gives me errors.
expected 'while' before numeric constant
expected ')' before numeric constant
expected '(' before numeric token.
Last edited on
Thank you again vlad for your reply it somehow made me
go back to what has always been me problem (the placement of braces)
and I was able to fix the prog. now it runs ok.
Many thanks.
I did not test the code but it could look something as

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
60
61
62
63
64
65
66
// calc5_cpp //
 
#include <string>
#include <iostream>

using namespace std;
 
int main()
{
   const float INITIAL_BALANCE = 3500.00f;
   float Bank = INITIAL_BALANCE;
   char again;

   do
   {
      int input;
      cout << "Enter amount to credit (1) or debit (2) the bank ";
      cout << " Enter an option 1 or 2" << endl << endl;

      cin >> input;
 
      switch ( input )
      {
      case 1:
      {
         float cr;

         cout << endl;
         cout << " Enter amount to credit the Bank." << endl;
         cin >> cr;

         Bank += cr;

         cout << "Bank is now " << Bank  << endl;
         break;
      }

      case 2:
      {
         float dr;

         cout << endl;
         cout << " Enter amount to debit the Bank. " << endl;
         cin  >>  dr;

         Bank -= dr;

         cout << "Bank is now " << Bank  << endl;
         break;
      }

      case default:
      {
         cout << "Error: invalid entry" << endl;
         break;
      }
      }
      
      cout << " Would you like to restart( y or n)";
      cin >> again;
   }  while( again == 'y' || again == 'Y' )

   cout << "Your ending balance is:" << Bank <<endl;

   return 0;
}
Last edited on
Thank you again Vlad I have made a copy of your prog.
It will be a big help for me thank you.
Topic archived. No new replies allowed.