0
Is anyone good with C++ and is willing to help?
I have to modify a program I made using a senitel loop and I have no clue where to start.
8 Antworten
+ 5
Yes, I will be happy to help.
Can you post the initial code for my reference?
What modifications do you need to make?
+ 4
@Nae Codebell
Try this :
#include<iostream>
using namespace std;
int main ()
{
float tot = 0; // declare
cout<<" PLEASE ENTER A NUMBER \n";
do
{
cin>>tot;
if(tot==-1) break;
if(tot<0)
cout<<" INVALID \n";
if(tot<=20000)
tot = tot + 0.2 * tot;
else
if(tot>20000)
if(tot<40000)
tot = tot + 0.1 * tot;
cout<<" tot is "<<tot<<endl;
} while ( tot != -1) ;
system("pause");
return 0;
}
+ 3
@Noe
The do{} while(...); is another type of loop in C++. Basically, it is an exit controlled loop, and is guaranteed to run atleast once. Thus i use it as I don't know the value of tot for the first time.
The curly brackets after do, contain the code that is to be iterated multiple times, and the loop stops when we get a -1.
+ 1
#include<iostream>
using namespace std;
int main ()
{
float tot = 0; // declare
cout<<" PLEASE ENTER A NUMBER \n";
cin>>tot;
if(tot<0)
cout<<" INVALID \n";
if(tot<=20000)
tot = tot + 0.2 * tot;
else
if(tot>20000)
if(tot<40000)
tot = tot + 0.1 * tot;
cout<<" tot is "<<tot<<endl;
system("pause");
return 0;
}
+ 1
Modfiy your RAISE program to accept and test salaries until user enters -1 using a sentinel loop.
+ 1
Where did you enter the loop? And why did you add the word do?
+ 1
Okay thank you for the explanation.
+ 1
I will test it