Need some help on my code. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Need some help on my code.

Am trying to make a lil program that is about if a worker sells 100 pencils, he's got a commission of 5%. But if he's not selling 100 pencils or only sells 99 pencils then he's got any commission. Where am I wrong at ? please correct me! Thanks in advance! #include <iostream> using namespace std; int main(){ int pencil; cout<<"Write pencils"; cin>>pencil; if(0.5*100); { cout <<"Commission earned"<<endl; } { else cout<<"0 commission"<<endl; } }

17th Feb 2018, 6:57 AM
Crazy Roll
Crazy Roll - avatar
15 Answers
+ 13
You are welcome..😀 All of us are learners and with practice we get more experiance and the same for you. Asking is the key of learning, so don't hesitate to ask. With progrramming you must be specific in order to get the right decision. Wish you the best..😉
18th Feb 2018, 7:41 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 12
18th Feb 2018, 4:08 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
you does not mention that in your question. in order to calculate the commisson you must specify the price of pencil not only the quantity. Please correct your question and make it clear in order to get the correct answer.
18th Feb 2018, 8:10 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
100 pencil is the quantity but where is the price to calculate the 5% commission from the total price of quantity. ex: if the price of pencel is: 0.5$ and he sell 120 then he get 5% as commission from the total price. total price = total quantity * price per unit = 120 * 0.5$ = 60$ commission = 5% = (5 * 60$)/100 = 3$. in this case you can calculate commission. check the below updated code: https://code.sololearn.com/cPRan55WnfKi/?ref=app
18th Feb 2018, 3:51 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 10
when you run your program this message appear to insert the value you want. if you insert 100 then it will asign the variable 'pencil' a value 100(that mean pencil = 100). the output will be: Commission earned if you insert 50 then the output will be 0 commission try it and if you have any question don't worry to ask.
17th Feb 2018, 4:43 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 9
you can add '\n' or 'endl' to print each sentence on a separete line. also you can print the value you inserted #include <iostream> using namespace std; int main() { int pencil; cout<<"Write pencils = "; cin>>pencil; // here you can add the value of pencil //and make a new line with 'endl' cout << pencil << endl; if( pencil >= 100){ cout << "Commission earned" << endl; } else{ cout <<"0 commission" << endl; } }
17th Feb 2018, 5:04 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 8
hi @CrazyRoll you must check the inserted value (pencil) if( pencil >= 100){ cout << "Commission earned" << endl; }else{ cout <<"0 commission" << endl; }
17th Feb 2018, 11:31 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 1
do u mind to try my code and see what happens ? I did what u told me and still have problems I guess #include <iostream> using namespace std; int main() { int pencil; cout<<"Write pencils"; cin>>pencil; if( pencil >= 100){ cout << "Commission earned" << endl; } else{ cout <<"0 commission" << endl; } }
17th Feb 2018, 4:16 PM
Crazy Roll
Crazy Roll - avatar
+ 1
tho I don't know what it means when every time I run it appears on the screen that says that I have to custom input or use new lines to separate multiple inputs
17th Feb 2018, 4:22 PM
Crazy Roll
Crazy Roll - avatar
+ 1
well, I inserted 100 just appeared Write pencils Commission and when I inserted 5 it appeared Write pencils0Commission
17th Feb 2018, 4:49 PM
Crazy Roll
Crazy Roll - avatar
+ 1
Thank u so much. it's working. sorry for not telling u the price tho. It's because my professor didn't tell me if it has a price, he just said exactly what I post here.
18th Feb 2018, 6:52 PM
Crazy Roll
Crazy Roll - avatar
0
well, the operation is not working tho
18th Feb 2018, 2:36 AM
Crazy Roll
Crazy Roll - avatar
0
well, the operation is not working tho
18th Feb 2018, 2:37 AM
Crazy Roll
Crazy Roll - avatar
0
Dude, when I insert 100, it suppose to show 5 , isn't it ?
18th Feb 2018, 4:22 AM
Crazy Roll
Crazy Roll - avatar
0
I did. If he sells 100 pencils then he earns 5%. or if he doesn't sell 100 pencils he doesn't earn anything.
18th Feb 2018, 3:08 PM
Crazy Roll
Crazy Roll - avatar