Help with Event Controlled Loop.

This is a discussion on Help with Event Controlled Loop. within the C++ Programming forums, part of the General Programming Boards category; I am just a student who have a programming class that is not related to my course. So I am ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    5

    Help with Event Controlled Loop.

    I am just a student who have a programming class that is not related to my course.
    So I am helping for your help guys.

    This is the needed output:

    Enter Amount Borrowed: 5000
    Payment # 1: 1000
    Current Balance: 4000

    Payment # 2: 2000
    Current Balance: 2000

    Payment # 3: 1000
    Current Balance: 1000

    Payment # 4: 100
    Current Balance: 900

    Payment # 5: 500
    Current Balance: 400

    Payment # 6: 400
    Current Balance: 0

    YOU ARE PAID!




    I try my best to answer this. When i insert the code below, its not adding the input value while loop. For example, The amount borrowed is 5000, i enter 1000. So the current balance is 4000, when i enter 500, it must be 3500, right ? but its still 4500 on the screen. So its not adding while loop. here's my code:


    Code:
    // HARD.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    void main()
    {
    	int num=0,				//input value
    		   ab,				//Amount Borrowed		
    		  p=0,				//payment number counter
    	         cb=0;				//Current Balance 
        float	
    		 sum=0;				//add
    
    		cout<<"Enter Amount Borrowed:";
    		cin>>ab;
    
    		while(ab!=0)
           {	
    		sum+=num;
    		p=p+1;
    		cout<<"Payment#"<<p<<":";
    		cin>>num;
    		
    		cb=ab-num;
    		cout<<"Current Balance:"<<cb<<endl;
           }
    		cout<<"You are Paid";
    
    getch();
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Were you planning to change ab at some point. (If not, how are you going to ever get out of your loop?)

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    Quote Originally Posted by tabstop View Post
    Were you planning to change ab at some point. (If not, how are you going to ever get out of your loop?)
    Can you help me ? Can you change the code ? That's our assignment.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I can the change the code to all sorts of things. What you need to do is to change the code so that it works -- your loop runs on ab, so either change your loop to run on something else, or make sure ab changes inside the loop. Which one you need to do depends on how you want the program to work, and only you know how you want the program to work.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    Quote Originally Posted by tabstop View Post
    I can the change the code to all sorts of things. What you need to do is to change the code so that it works -- your loop runs on ab, so either change your loop to run on something else, or make sure ab changes inside the loop. Which one you need to do depends on how you want the program to work, and only you know how you want the program to work.
    No, That's just our assignment. That's not my invention, you know what i mean ? The given output above is the needed program. Please help me.

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    Quote Originally Posted by tabstop View Post
    I can the change the code to all sorts of things. What you need to do is to change the code so that it works -- your loop runs on ab, so either change your loop to run on something else, or make sure ab changes inside the loop. Which one you need to do depends on how you want the program to work, and only you know how you want the program to work.
    If someone will ask you to make a program with an output stated above, What code will you give ?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should read the bits at the top of the board, like this

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    Quote Originally Posted by tabstop View Post
    You should read the bits at the top of the board, like this
    I am just asking to correct my code. I am not asking for the answers without my own asnwer. pls...

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have been told how to correct your code. Now do so.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sentinel controlled do-while loop
    By theCanuck in forum C++ Programming
    Replies: 10
    Last Post: 03-23-2011, 12:07 AM
  2. Main-loop vs Event driven.
    By Adamkromm in forum Game Programming
    Replies: 2
    Last Post: 10-06-2010, 06:16 PM
  3. Poll event loop
    By rogster001 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2009, 05:28 AM
  4. Sentinel controlled loop
    By arjay in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 05:30 AM
  5. flag-controlled while loop
    By azsquall in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2008, 03:48 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21