0

How can i complete ticket office module project in c++ ? Sololearn to achieve certificate....

7th Jan 2021, 5:26 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
24 Réponses
+ 14
I'm glad that it worked for you. But you should try making a code which will find the smallest of the array instead of hard coding with all those if-else statements.. For your reference.. Hope you'll find some inspiration 😉 #include <iostream> using namespace std; double findYoungest(int arr[]){ double min = arr[0]; for(int i=0; i<5; i++) { if(min>arr[i]) { min=arr[i]; } } return min; } int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } double discount = 50 - (findYoungest(ages)*0.5); cout<< discount; return 0; }
7th Jan 2021, 5:56 AM
Minho
Minho - avatar
+ 6
Why the last line "everything is same" ? You can't write anything which is not expected in the code coach.
7th Jan 2021, 5:45 AM
Minho
Minho - avatar
+ 5
You're welcome 😊
7th Jan 2021, 6:19 AM
Minho
Minho - avatar
+ 4
By making the appropriate code which passes all the testcases?
7th Jan 2021, 5:35 AM
Minho
Minho - avatar
+ 4
Can please you link your code here so others can see it and debug accordingly?
7th Jan 2021, 5:38 AM
Minho
Minho - avatar
+ 4
My code (I think it's as simple as it could get): #include <iostream> using namespace std; int main() { int ages [5], arrN; for (arrN = 0; arrN < 5; arrN++) { cin >> ages [arrN]; } float min = ages [0]; for(int arrN = 0; arrN < 5 ;++arrN){ if(ages[arrN] <= min){ min = ages[arrN]; }} cout << 50 -50 * min / 100 << endl; return 0;}
15th Mar 2021, 11:05 PM
Oxdan
Oxdan - avatar
+ 2
This is what I used. Passed with it. #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here double smallest = ages[0] ; for ( int i=1; i < sizeof(ages)/sizeof(ages[0]); ++i ) if ( ages[i] < smallest ) smallest = ages[i] ; cout << 50 - smallest / 100 * 50; return 0; }
26th Nov 2021, 9:47 PM
Catena Gaming
Catena Gaming - avatar
+ 1
I found the post with the 2nd array and using unnecessary doubles more confusing so here's how I did it: #include <iostream> using namespace std; int main() { int ages[5]; int i; int min; for (i = 0; i < 5;++i) { cin >> ages[i]; } min=ages[0]; for (i=0;i<5;i++) { if (min>ages[i]) { min=ages[i]; } } cout<<50-(min*0.5)<<endl; return 0; }
10th Mar 2021, 3:45 AM
Salvatore Iaquinto
Salvatore Iaquinto - avatar
+ 1
This is perfect code: #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int little = 9999999999999; //No one can be this age. double k; for (int i = 0; i < 5; i++) { if (ages[i] < little) { little = ages[i]; k = ages[i]; } } cout << 50 - 50 * k / 100; return 0; }
8th Jun 2022, 1:24 PM
Yiğithan
Yiğithan - avatar
0
I have written a code which passes in 1st, 2nd, 4th and 5th test cases, but in 3rd case it is showing that i have written wrong code, and 3rd case is hidden, i can't even see what the case is...
7th Jan 2021, 5:38 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
#include <iostream> using namespace std; int main() { float ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here float doll=50; float a=ages[0]; float b=ages[1]; float c=ages[2]; float d=ages[3]; float e=ages[4]; float tem; float p; if(a<b&&a<c&&a<d&&a<e) { tem=doll*a/100; p=doll-tem; cout << p; } else if(b<a&&b<c&&b<d&&b<e) { tem=doll*b/100; p=doll-tem; cout << p; } else if(c<a&&c<b&&c<d&&c<e) { tem=doll*c/100; p=doll-tem; cout << p; } else if(d<a&&d<b&&d<c&&d<e) { tem=doll*d/100; p=doll-tem; cout << p; } else if(e<a&&e<b&&e<c&&e<d) { tem=doll*e/100; p=doll-tem; cout << p; } else { cout << "everthing is same"; } return 0; }
7th Jan 2021, 5:40 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
This is the code
7th Jan 2021, 5:40 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
It is like when all the values are provided in inputs are same.....
7th Jan 2021, 5:47 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
Hey thanks ❤😊 it's done I just removed last else part and renamed else if as else and now all the test cases are satisfied😊....
7th Jan 2021, 5:51 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
Yes ✅it's good your given code is short and easy to understand.... Thank you ☺
7th Jan 2021, 6:10 AM
Sumit S. Bhardwaj
Sumit S. Bhardwaj - avatar
0
Well arr is usual reserved for arrays not the name for a regular integer. Float is not needed for regular integers. Not like the cashier will type in they are 15.6 years old. Also <= is unnecessary as if the age is the same there is no reason to change the value of the variable. You only need < or > depending on which variable you put first. Otherwise it's the same as mine. I just spaced mine out for easy reading.
19th Mar 2021, 10:56 PM
Salvatore Iaquinto
Salvatore Iaquinto - avatar
0
take a look in my codes saved u will find solution
3rd Aug 2021, 3:17 PM
Salah Eddin Khiat
Salah Eddin Khiat - avatar
0
#include <iostream> using namespace std; int main() { int ages[5], arr; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } float min = ages[0]; for(int arr = 0; arr < 5 ;++arr) { if(ages[arr] <= min) { min = ages[arr]; } } cout << 50 - (min * 50) / 100; return 0; }
31st Oct 2021, 7:38 PM
the ice
the ice - avatar
0
#include <iostream> using namespace std; int main() { int ages[5]; double younger; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here younger = ages[0]; for (int i = 0; i < 5; ++i) { if (younger > ages[i]) { younger = ages[i]; } } double discount = 50-((younger*50)/100); cout << discount << endl; return 0; }
1st Nov 2021, 3:14 PM
Alaa JALLELI
Alaa JALLELI - avatar
0
#include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if (i>=1){ if (ages[i]<ages[0]){ ages[0]=ages[i]; }} } cout<<float(50-5*ages[0]/10.0); }
1st Jan 2022, 12:51 PM
Ayu Lestari Gunawan