GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jan-2009, 19:26
bostero22 bostero22 is offline
Junior Member
 
Join Date: Oct 2008
Posts: 50
bostero22 is on a distinguished road

Error "cannot find symbol"


hello, I am new to java programming and im trying to do a "do while" loop in this program. However it gives me an error "cannot find symbol" I dont understand what I am doing wrong, because i tried using the variable transactions the same way using just a while loop and it worked just fine. Please any help?

JAVA Code:
do
     {
         Scanner tran = new Scanner (System.in);
     
        System.out.println("How Many Transactions would you like to do in Month: " + count + " (Entering a negative number will terminate the program)");
     
     int transactions = tran.nextInt();
     
        for (int insideCount = 1; insideCount <= transactions; insideCount++)
        {
            Scanner checkTran = new Scanner (System.in);
            System.out.println("Please, Transacion #" + insideCount + "(A negative number will result in a withdrawal");
            double amount = checkTran.nextDouble();

            if (amount > 0)
            {
                testAccount.setDeposit(amount);
            }
            else if (amount < 0)
            {
                testAccount.setWithdrawal(amount);
            }
            
        }
     
            
     } while (transactions > 0); //here is the error
     } 
     }
  #2  
Old 22-Jan-2009, 00:37
blakekl's Avatar
blakekl blakekl is offline
Junior Member
 
Join Date: Nov 2007
Posts: 35
blakekl will become famous soon enough

Re: Please, I can't find where is the mistake in This Program


The problem is that the variable transactions is outside the scope of the while() comparison because you declared the transactions variable inside the do{} statement. Try this:

JAVA Code:
System.out.println("How Many Transactions would you like to do in Month: " + count + " (Entering a negative number will terminate the program)");
Scanner tran = new Scanner (System.in);
int transactions = tran.nextInt();
do
{
   for (int insideCount = 1; insideCount <= transactions; insideCount++)
   {
      Scanner checkTran = new Scanner (System.in);
      System.out.println("Please, Transacion #" + insideCount + "(A negative number will result in a withdrawal");
      double amount = checkTran.nextDouble();

      if (amount > 0)
      {
         testAccount.setDeposit(amount);
      }
      else if (amount < 0)
      {
         testAccount.setWithdrawal(amount);
      }
            
   }
} while (transactions > 0);
  #3  
Old 23-Jan-2009, 13:52
bostero22 bostero22 is offline
Junior Member
 
Join Date: Oct 2008
Posts: 50
bostero22 is on a distinguished road

Re: Error "cannot find symbol"


thanks it worked :]
  #4  
Old 23-Jan-2009, 14:26
blakekl's Avatar
blakekl blakekl is offline
Junior Member
 
Join Date: Nov 2007
Posts: 35
blakekl will become famous soon enough

Re: Error "cannot find symbol"


No problem. Remember the scope of your variables.
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 09:24
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Help with a complex program lordfuoco C++ Forum 5 24-Jun-2006 06:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:52.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.