Require user action before continuing..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 3
Reputation: Beginerman is an unknown quantity at this point 
Solved Threads: 0
Beginerman Beginerman is offline Offline
Newbie Poster

Require user action before continuing..

 
0
  #1
Apr 19th, 2009
I need a little help with the below if statement. What i would like to have happen is for the loop caused by the first if statment to also be conditional to a second if statement that will pause the loop output and require user interaction to either continue displaying the looped information or quit. My thought was to pause the loop after every 12 lines of output and require the user to continue or exit the loop. Any help is greatly apreciated. As you can see below i was not succeful in my attempt. Thanks again.

 for (int a = 1; a < months+1; a++)
	{
	if (a < months){
	currInt = principal * interest;
	principalPaid = payment - currInt;
	principal = principal - principalPaid;
cout << "Payment Number" << "\tPayment Amount" << "\tInterest Paid" << "\tBalance "<< endl;
cout << a << "\t\t$" <<payment << "\t$" <<currInt << "\t\t$" <<principal << endl;
if (a = months+12){
          cout << "Would you like to Continue (Y/N)?\n";
           cin >> R;
           while (R == 'y'  ||  R == 'Y');
return 0;
	}
            }
	else {
cout << endl;
cout << a << "\t*******Your loan is paid in FULL!!*******" << endl;
}
Last edited by Beginerman; Apr 19th, 2009 at 11:33 pm. Reason: additional comment
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 79
Reputation: MatEpp is an unknown quantity at this point 
Solved Threads: 12
MatEpp MatEpp is offline Offline
Junior Poster in Training

Re: Require user action before continuing..

 
0
  #2
Apr 19th, 2009
I think you need another ending bracket for the for loop.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 792
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Require user action before continuing..

 
0
  #3
Apr 20th, 2009
I have not seen your code thoroghly but the immediate thing I would like to point out it this:
if (a = months+12){ as you may see you have used a = rather than ==. In c++( and even in C) = will always evaluate true. To test for a condition == should be used.
So change it too ==.
Last edited by siddhant3s; Apr 20th, 2009 at 3:30 am.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: Beginerman is an unknown quantity at this point 
Solved Threads: 0
Beginerman Beginerman is offline Offline
Newbie Poster

Re: Require user action before continuing..

 
0
  #4
Apr 20th, 2009
OK. I have changed the conditional operator to the == and the additional bracket has been added but now the output will stop after the first line of output data. I guess i may not be evaluating the months + 12 condition correctly. I originally wanted it to stop after every 12 lines of output data and ask to continue. I think im almost there but still need a little more assistance.

  1. if (a == months+12){
  2. cout << "Would you like to Continue (Y/N)?\n";
  3. cin >> R;
  4. } while (R == 'y' || R == 'Y');
  5. return 0;
Last edited by Beginerman; Apr 20th, 2009 at 8:45 am. Reason: additional comment
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 792
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Require user action before continuing..

 
0
  #5
Apr 20th, 2009
>>I originally wanted it to stop after every 12 lines of output
Your condition is wrong.
Basically you want to stop at every multiple of 12. that is when a is 12,24,36...
That is a divided by 12 should yield no remainder.
So change your condiditon to :
  1. if(a %12==0)
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: Beginerman is an unknown quantity at this point 
Solved Threads: 0
Beginerman Beginerman is offline Offline
Newbie Poster

Re: Require user action before continuing..

 
0
  #6
Apr 23rd, 2009
Problem solved for my first question. I thank everyone for your help.
I solved the problem as follows.
  1. //Beak loop for every 15 lines of displayed payments
  2. if( a %15== 0)
  3. {
  4. cout << "Press Enter to continue.";
  5. cin.get();
  6. }
  7. }

Next question:
I know the text highlighted in red below is incorrect. So, i am asking if anyone knows of how i can validate whether or not the user has entered a number and if they did not enter a number then i want to offer them to re-enter information or exit the program. I have searched both my educational document and the net and keep coming back to first converting the user input data into a string and then validate each character in the string. However, i do not want to go this far with this code at all. I simply want to validate if it is a number or not and then throw an error and ask to re-enter the entry. If you kind programming gurus believe the string validation is the best method then please give me an example of how to do this with ease. I appreciate your help immensly.

#include <iostream>
#include <math.h>
#include <iomanip>
#include <cctype>

using namespace std;

int main()
{
	char R; //response variable
    do{
	//Declaring variables
	float loanAmt;  
	int months;    
	int loanTerm;   
	float loanRate;  
	float principal;
	float principalPaid;
	float currInt;
	float payment, interest; 
	//Beginning of user input data
         cout << endl;
	     cout << "Enter the Loan Principal Amount: ";
         cin >> loanAmt;
		 if (!isdigit(R))
		 {
			cout << "You entered an invalid Loan Amount" <<endl;
			cout << "please enter a valid amount." <<endl;		
			return main();  
		 }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC