473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Using centinel

I want this program to stop after you enter 0 in for the customer number
and not have to enter 0 for all fields before it ends. Please help.. Thanks

#include <iostream.h>

int main()
{
float principle = 1;
float ni = 1; // number of payments per year
int count = 0;// total loans processes
int cust = 1; //customer number
float intrest = 1;// interest charges
float tpay = 0;//total payments
float rate = 1;//intrest in percentages

while (principle != 0)
{
cout <<"\nEnter customer number\n";
cin >> cust;

cout <<"\nEnter payments per year\n";
cin >> ni;

cout << "\nEnter intrest charge\n";
cin >> intrest;

cout << "\nEnter principal loan amount\n";
cin >> principle;

cout << "\Enter total numbers of payments\n";
cin >>tpay;

if (principle == 0)
cout << "the end\n";
else count++;
if (principle > 0)

rate = (2 * ni * intrest* 100) / (principle * (tpay + 1));

if (principle>0)
cout << "customer number & principle loan amt: "<< cust << " " <<
principle << " ";
if (principle > 0)
cout << " Interest in percentages " << rate << " % " << '\n';
}
cout << "Total loans processed " << count << '\n';

return 0;
}


Jul 22 '05 #1
3 1093
"d.j." <de***@hotmail.com> wrote...
I want this program to stop after you enter 0 in for the customer number
and not have to enter 0 for all fields before it ends. Please help.. Thanks
#include <iostream.h>

int main()
{
float principle = 1;
float ni = 1; // number of payments per year
int count = 0;// total loans processes
int cust = 1; //customer number
float intrest = 1;// interest charges
float tpay = 0;//total payments
float rate = 1;//intrest in percentages

while (principle != 0)
{
cout <<"\nEnter customer number\n";
cin >> cust;
So, here your program already knows the 'cust' value. Check if it's
the "sentinel" value and bail out of the 'while' loop. Read about
'if' statement and 'break' statement.

cout <<"\nEnter payments per year\n";
cin >> ni;

cout << "\nEnter intrest charge\n";
cin >> intrest;

cout << "\nEnter principal loan amount\n";
cin >> principle;

cout << "\Enter total numbers of payments\n";
cin >>tpay;

if (principle == 0)
cout << "the end\n";
else count++;
if (principle > 0)

rate = (2 * ni * intrest* 100) / (principle * (tpay + 1));

if (principle>0)
cout << "customer number & principle loan amt: "<< cust << " " <<
principle << " ";
if (principle > 0)
cout << " Interest in percentages " << rate << " % " << '\n';
}
cout << "Total loans processed " << count << '\n';

return 0;
}


Jul 22 '05 #2

"d.j." <de***@hotmail.com> wrote in message
news:jd****************@eagle.america.net...
I want this program to stop after you enter 0 in for the customer number
and not have to enter 0 for all fields before it ends. Please help.. Thanks
Simple enough.
#include <iostream.h>

int main()
{
float principle = 1;
float ni = 1; // number of payments per year
int count = 0;// total loans processes
int cust = 1; //customer number
float intrest = 1;// interest charges
float tpay = 0;//total payments
float rate = 1;//intrest in percentages

while (principle != 0)
{
cout <<"\nEnter customer number\n";
cin >> cust;


if (cust == 0)
break;

john
Jul 22 '05 #3
great thanks john...

John Harrison wrote:
"d.j." <de***@hotmail.com> wrote in message
news:jd****************@eagle.america.net...
I want this program to stop after you enter 0 in for the customer number
and not have to enter 0 for all fields before it ends. Please help..


Thanks
Simple enough.

#include <iostream.h>

int main()
{
float principle = 1;
float ni = 1; // number of payments per year
int count = 0;// total loans processes
int cust = 1; //customer number
float intrest = 1;// interest charges
float tpay = 0;//total payments
float rate = 1;//intrest in percentages

while (principle != 0)
{
cout <<"\nEnter customer number\n";
cin >> cust;

if (cust == 0)
break;

john


Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
1
by: Matt | last post by:
Hi everyone, I'm using the command mysqlcheck --all-databases --auto-repair --silent and I see these warnings (listed below) on a daily occurrence. Is mysqlcheck causing these warnings? I...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.