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.

12th Sep 2017, 4:19 PM
Nae Codebell
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?
12th Sep 2017, 4:37 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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; }
12th Sep 2017, 4:46 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
12th Sep 2017, 6:02 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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; }
12th Sep 2017, 4:40 PM
Nae Codebell
+ 1
Modfiy your RAISE program to accept and test salaries until user enters -1 using a sentinel loop.
12th Sep 2017, 4:41 PM
Nae Codebell
+ 1
Where did you enter the loop? And why did you add the word do?
12th Sep 2017, 5:59 PM
Nae Codebell
+ 1
Okay thank you for the explanation.
12th Sep 2017, 6:05 PM
Nae Codebell
+ 1
I will test it
12th Sep 2017, 6:05 PM
Nae Codebell