CFanatic

Go Back   CFanatic > Programming > C Programming

Join CFanatic Forum Now

while loop help topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2010, 03:52 PM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
nate201 is on a distinguished road
| More
while loop help

I have to make a program for class to maintain a bank balance. The problem I am having is I can make all my deposits then my withdrawals, but i cant return to deposit after i make a withdrawal. How can I make it with only one while loop so i can switch between the two without any problems?
Code:
int main()
{
        double total = 0.0;

        double x;

        char resp;

        explanation();

        printf("BANK ACCOUNT PROGRAM\n");
        printf("--------------------\n\n");

        printf("Please Enter the old balance: ");
        scanf("%lf%*c",&total);
        printf("Enter the transactions now.\n");
        printf("Enter an \"F\" for the transaction type when you are finished.\n\n");
        printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
        scanf("%c%*c",&resp);

        while(resp=='D') 
        {
                printf("Amount: ");
                scanf("%lf%*c",&x);
                
                total = total + x;  

                printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
                scanf("%c%*c",&resp);
        }

        while(resp=='W')
        {
                printf("Amount: ");
                scanf("%lf%*c",&x);

                total = total - x;

                printf("Transaction Type (D=Deposit, W=Withdrawal, F=Finished): ");
                scanf("%c%*c",&resp);
        }

        while(resp=='F')
        {
                printf("Your ending balance is: $%8.2lf\n",total);
                printf("Program Ending");
        }
}
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Couting the attempts in a 'while' loop? HannahMar C# Programming 4 11-23-2010 10:33 AM
What is loop techinspiration C Programming 3 08-07-2010 06:11 AM
loop program s.kavita C++ Programming 1 07-25-2010 08:35 AM
Loop problem creative C Programming 6 04-02-2010 09:17 PM
Do While loop syntax codeunlock C# Programming 1 04-29-2007 08:31 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:46 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board