| | |
Require user action before continuing..
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
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
I have not seen your code thoroghly but the immediate thing I would like to point out it this:
So change it too ==.
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
(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
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
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.
C++ Syntax (Toggle Plain Text)
if (a == months+12){ cout << "Would you like to Continue (Y/N)?\n"; cin >> R; } while (R == 'y' || R == 'Y'); return 0;
Last edited by Beginerman; Apr 20th, 2009 at 8:45 am. Reason: additional comment
>>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 :
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 :
C++ Syntax (Toggle Plain Text)
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
(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
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
Problem solved for my first question. I thank everyone for your help.
I solved the problem as follows.
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.
I solved the problem as follows.
C++ Syntax (Toggle Plain Text)
//Beak loop for every 15 lines of displayed payments if( a %15== 0) { cout << "Press Enter to continue."; cin.get(); } }
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();
}![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: i have a problem in programming
- Next Thread: Serial Port Programming Visual C++
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





