0
How can i complete ticket office module project in c++ ? Sololearn to achieve certificate....
24 ответов
+ 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;
}
+ 6
Why the last line "everything is same" ?
You can't write anything which is not expected in the code coach.
+ 5
You're welcome 😊
+ 4
By making the appropriate code which passes all the testcases?
+ 4
Can please you link your code here so others can see it and debug accordingly?
+ 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;}
+ 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;
}
+ 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;
}
+ 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;
}
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...
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;
}
0
This is the code
0
It is like when all the values are provided in inputs are same.....
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😊....
0
Yes ✅it's good your given code is short and easy to understand.... Thank you ☺
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.
0
take a look in my codes saved u will find solution
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;
}
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;
}
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);
}