Post: challenging c++ problem(at least challenging to me)
04-21-2011, 10:09 PM #1
|C++|
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); you guys prob know about
c = (a>b) ? a : b
well if you do you can help....
i am trying to do this
    
c = (person1>person2 && person1>person3 && person1>person4 && person1>person5 && person1>person6 &&person2>person1 && person2>person3 && person2>person4 && person2>person5 && person2>person6 && person3>person1 && person3>person2 && person3>person4 && person3>person5 && person3>person6 && person4>person1 && person4>person2 && person4>person3 && person4>person5 && person4>person6 && person5>person1 && person5>person2 && person5>person3 && person5>person4 && person5>person6 && person6>person1 && person6>person2 && person6>person3 && person6>person4 && person6>person5) ? person1 : person2 && person3 : person4 && person5 : person6;


when it comes to the
    
person1 : person2 && person3 : person4 && person5 : person6;

at first i didnt have the "&&" operators i had ":" between them all but that didnt work so i separated each set of two functions with the && operator.

so is there any way to compare more than 2 functions at a time??
better yet is there a way i can see which is bigger out of them ALL(using or not using this message?)
+rep if you fix it for me

heres the whole code for extra
    

#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
void person6();
void person5();
void person4();
void person3();
void person2();
void person1();
int c;
int numberofpancakes1;
int numberofpancakes2;
int numberofpancakes3;
int numberofpancakes4;
int numberofpancakes5;
int numberofpancakes6;

void person1()
{
cin>>numberofpancakes1;
cout<<"Person 1 ate : "<<numberofpancakes1<<"pancakes \n";
person2();
}

void person2()
{
cin>>numberofpancakes2;
cout<<"Person 2 ate : "<<numberofpancakes2<<"pancakes \n";
person3();
}

void person3()
{
cin>>numberofpancakes3;
cout<<"Person 3 ate : "<<numberofpancakes3<<"pancakes \n";
person4();
}

void person4()
{
cin>>numberofpancakes4;
cout<<"Person 4 ate : "<<numberofpancakes4<<"pancakes \n";
person5();
}

void person5()
{
cin>>numberofpancakes5;
cout<<"Person 5 ate : "<<numberofpancakes5<<"pancakes \n";
person6();
}

void person6()
{
cin>>numberofpancakes6;
cout<<"Person 6 ate : "<<numberofpancakes6<<"pancakes \n";
cout<<"Would you like to know who ate the most? (Y/N)";
char answer;
cin>> answer;
if(answer == 'Y'Winky Winky
c = (person1>person2 && person1>person3 && person1>person4 && person1>person5 && person1>person6 &&person2>person1 && person2>person3 && person2>person4 && person2>person5 && person2>person6 && person3>person1 && person3>person2 && person3>person4 && person3>person5 && person3>person6 && person4>person1 && person4>person2 && person4>person3 && person4>person5 && person4>person6 && person5>person1 && person5>person2 && person5>person3 && person5>person4 && person5>person6 && person6>person1 && person6>person2 && person6>person3 && person6>person4 && person6>person5) ? person1 : person2 && person3 : person4 && person5 : person6;
}

int main()
{
cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";
person1();
char f;
cin>> f;
return 0;
}
04-21-2011, 11:21 PM #2
This is the best way I can do it going towards your way.

    
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void person6();
void person5();
void person4();
void person3();
void person2();
void person1();
int c;
int numberofpancakes1;
int numberofpancakes2;
int numberofpancakes3;
int numberofpancakes4;
int numberofpancakes5;
int numberofpancakes6;

void check()
{
cout<<"Would you like to know who ate the most? (Y/N)";
string answer;
cin>> answer;
if(answer == "Y")
{
int max;
int max2 = 1;
max = numberofpancakes1;
if (max < numberofpancakes2)
{
max = numberofpancakes2;
max2 = 2;
}
if (max < numberofpancakes3)
{
max = numberofpancakes3;
max2 = 3;
}
if (max < numberofpancakes4)
{
max = numberofpancakes4;
max2 = 4;
}
if (max < numberofpancakes5)
{
max = numberofpancakes5;
max2 = 5;
}
if (max < numberofpancakes6)
{
max = numberofpancakes6;
max2 = 6;
}

if (max2 == 1)
{
cout << "Person 1 at the most pancakes which was: " << max;
}
if (max2 == 2)
{
cout << "Person 2 at the most pancakes which was: " << max;
}
if (max2 == 3)
{
cout << "Person 3 at the most pancakes which was: " << max;
}
if (max2 == 4)
{
cout << "Person 4 at the most pancakes which was: " << max;
}
if (max2 == 5)
{
cout << "Person 5 at the most pancakes which was: " << max;
}
if (max2 == 6)
{
cout << "Person 6 at the most pancakes which was: " << max;
}
}
}
void person1()
{
cin>>numberofpancakes1;
cout<<"Person 1 ate : "<<numberofpancakes1<<"pancakes \n";
person2();
}

void person2()
{
cin>>numberofpancakes2;
cout<<"Person 2 ate : "<<numberofpancakes2<<"pancakes \n";
person3();
}

void person3()
{
cin>>numberofpancakes3;
cout<<"Person 3 ate : "<<numberofpancakes3<<"pancakes \n";
person4();
}

void person4()
{
cin>>numberofpancakes4;
cout<<"Person 4 ate : "<<numberofpancakes4<<"pancakes \n";
person5();
}

void person5()
{
cin>>numberofpancakes5;
cout<<"Person 5 ate : "<<numberofpancakes5<<"pancakes \n";
person6();
}

void person6()
{
cin>>numberofpancakes6;
cout<<"Person 6 ate : "<<numberofpancakes6<<"pancakes \n";
check();

}

int main()
{
cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";
person1();
char f;
cin>> f;
return 0;
}

The following user thanked MoBaTeY for this useful post:

|C++|
04-22-2011, 12:29 AM #3
|C++|
< ^ > < ^ >
Originally posted by MoBaTeY View Post
This is the best way I can do it going towards your way.

    
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void person6();
void person5();
void person4();
void person3();
void person2();
void person1();
int c;
int numberofpancakes1;
int numberofpancakes2;
int numberofpancakes3;
int numberofpancakes4;
int numberofpancakes5;
int numberofpancakes6;

void check()
{
cout<<"Would you like to know who ate the most? (Y/N)";
string answer;
cin>> answer;
if(answer == "Y")
{
int max;
int max2 = 1;
max = numberofpancakes1;
if (max < numberofpancakes2)
{
max = numberofpancakes2;
max2 = 2;
}
if (max < numberofpancakes3)
{
max = numberofpancakes3;
max2 = 3;
}
if (max < numberofpancakes4)
{
max = numberofpancakes4;
max2 = 4;
}
if (max < numberofpancakes5)
{
max = numberofpancakes5;
max2 = 5;
}
if (max < numberofpancakes6)
{
max = numberofpancakes6;
max2 = 6;
}

if (max2 == 1)
{
cout << "Person 1 at the most pancakes which was: " << max;
}
if (max2 == 2)
{
cout << "Person 2 at the most pancakes which was: " << max;
}
if (max2 == 3)
{
cout << "Person 3 at the most pancakes which was: " << max;
}
if (max2 == 4)
{
cout << "Person 4 at the most pancakes which was: " << max;
}
if (max2 == 5)
{
cout << "Person 5 at the most pancakes which was: " << max;
}
if (max2 == 6)
{
cout << "Person 6 at the most pancakes which was: " << max;
}
}
}
void person1()
{
cin>>numberofpancakes1;
cout<<"Person 1 ate : "<<numberofpancakes1<<"pancakes \n";
person2();
}

void person2()
{
cin>>numberofpancakes2;
cout<<"Person 2 ate : "<<numberofpancakes2<<"pancakes \n";
person3();
}

void person3()
{
cin>>numberofpancakes3;
cout<<"Person 3 ate : "<<numberofpancakes3<<"pancakes \n";
person4();
}

void person4()
{
cin>>numberofpancakes4;
cout<<"Person 4 ate : "<<numberofpancakes4<<"pancakes \n";
person5();
}

void person5()
{
cin>>numberofpancakes5;
cout<<"Person 5 ate : "<<numberofpancakes5<<"pancakes \n";
person6();
}

void person6()
{
cin>>numberofpancakes6;
cout<<"Person 6 ate : "<<numberofpancakes6<<"pancakes \n";
check();

}

int main()
{
cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";
person1();
char f;
cin>> f;
return 0;
}


nice job! sometimes i feel retarded, its like i know it but i just dont apply it. anyways i also see a way you can use for(...;...;...) in it/
04-22-2011, 01:13 AM #4
Originally posted by SLiiTH3R View Post
nice job! sometimes i feel retarded, its like i know it but i just dont apply it. anyways i also see a way you can use for(...;...;...) in it/


There are many ways to do it, I did a easy ti understand one towards your route.
04-22-2011, 09:20 PM #5
Originally posted by MoBaTeY View Post
This is the best way I can do it going towards your way.

    
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void person6();
void person5();
void person4();
void person3();
void person2();
void person1();
int c;
int numberofpancakes1;
int numberofpancakes2;
int numberofpancakes3;
int numberofpancakes4;
int numberofpancakes5;
int numberofpancakes6;

void check()
{
cout<<"Would you like to know who ate the most? (Y/N)";
string answer;
cin>> answer;
if(answer == "Y")
{
int max;
int max2 = 1;
max = numberofpancakes1;
if (max < numberofpancakes2)
{
max = numberofpancakes2;
max2 = 2;
}
if (max < numberofpancakes3)
{
max = numberofpancakes3;
max2 = 3;
}
if (max < numberofpancakes4)
{
max = numberofpancakes4;
max2 = 4;
}
if (max < numberofpancakes5)
{
max = numberofpancakes5;
max2 = 5;
}
if (max < numberofpancakes6)
{
max = numberofpancakes6;
max2 = 6;
}

if (max2 == 1)
{
cout << "Person 1 at the most pancakes which was: " << max;
}
if (max2 == 2)
{
cout << "Person 2 at the most pancakes which was: " << max;
}
if (max2 == 3)
{
cout << "Person 3 at the most pancakes which was: " << max;
}
if (max2 == 4)
{
cout << "Person 4 at the most pancakes which was: " << max;
}
if (max2 == 5)
{
cout << "Person 5 at the most pancakes which was: " << max;
}
if (max2 == 6)
{
cout << "Person 6 at the most pancakes which was: " << max;
}
}
}
void person1()
{
cin>>numberofpancakes1;
cout<<"Person 1 ate : "<<numberofpancakes1<<"pancakes \n";
person2();
}

void person2()
{
cin>>numberofpancakes2;
cout<<"Person 2 ate : "<<numberofpancakes2<<"pancakes \n";
person3();
}

void person3()
{
cin>>numberofpancakes3;
cout<<"Person 3 ate : "<<numberofpancakes3<<"pancakes \n";
person4();
}

void person4()
{
cin>>numberofpancakes4;
cout<<"Person 4 ate : "<<numberofpancakes4<<"pancakes \n";
person5();
}

void person5()
{
cin>>numberofpancakes5;
cout<<"Person 5 ate : "<<numberofpancakes5<<"pancakes \n";
person6();
}

void person6()
{
cin>>numberofpancakes6;
cout<<"Person 6 ate : "<<numberofpancakes6<<"pancakes \n";
check();

}

int main()
{
cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";
person1();
char f;
cin>> f;
return 0;
}


You should really put

        if(answer == "Y" || answer == "y")


Not

        if(answer == "Y") 


just incase some :n00b: comes along :L and use's the program
04-23-2011, 01:45 AM #6
You can, but it isnt a big deal.


Originally posted by ii
You should really put

        if(answer == "Y" || answer == "y")


Not

        if(answer == "Y") 


just incase some :n00b: comes along :L and use's the program
04-27-2011, 10:58 AM #7
Originally posted by SLiiTH3R View Post
you guys prob know about
c = (a>b) ? a : b
well if you do you can help....
i am trying to do this
    
c = (person1>person2 && person1>person3 && person1>person4 && person1>person5 && person1>person6 &&person2>person1 && person2>person3 && person2>person4 && person2>person5 && person2>person6 && person3>person1 && person3>person2 && person3>person4 && person3>person5 && person3>person6 && person4>person1 && person4>person2 && person4>person3 && person4>person5 && person4>person6 && person5>person1 && person5>person2 && person5>person3 && person5>person4 && person5>person6 && person6>person1 && person6>person2 && person6>person3 && person6>person4 && person6>person5) ? person1 : person2 && person3 : person4 && person5 : person6;


when it comes to the
    
person1 : person2 && person3 : person4 && person5 : person6;

at first i didnt have the "&&" operators i had ":" between them all but that didnt work so i separated each set of two functions with the && operator.

so is there any way to compare more than 2 functions at a time??
better yet is there a way i can see which is bigger out of them ALL(using or not using this message?)
+rep if you fix it for me

heres the whole code for extra
    

#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
void person6();
void person5();
void person4();
void person3();
void person2();
void person1();
int c;
int numberofpancakes1;
int numberofpancakes2;
int numberofpancakes3;
int numberofpancakes4;
int numberofpancakes5;
int numberofpancakes6;

void person1()
{
cin>>numberofpancakes1;
cout<<"Person 1 ate : "<<numberofpancakes1<<"pancakes \n";
person2();
}

void person2()
{
cin>>numberofpancakes2;
cout<<"Person 2 ate : "<<numberofpancakes2<<"pancakes \n";
person3();
}

void person3()
{
cin>>numberofpancakes3;
cout<<"Person 3 ate : "<<numberofpancakes3<<"pancakes \n";
person4();
}

void person4()
{
cin>>numberofpancakes4;
cout<<"Person 4 ate : "<<numberofpancakes4<<"pancakes \n";
person5();
}

void person5()
{
cin>>numberofpancakes5;
cout<<"Person 5 ate : "<<numberofpancakes5<<"pancakes \n";
person6();
}

void person6()
{
cin>>numberofpancakes6;
cout<<"Person 6 ate : "<<numberofpancakes6<<"pancakes \n";
cout<<"Would you like to know who ate the most? (Y/N)";
char answer;
cin>> answer;
if(answer == 'Y'Winky Winky
c = (person1>person2 && person1>person3 && person1>person4 && person1>person5 && person1>person6 &&person2>person1 && person2>person3 && person2>person4 && person2>person5 && person2>person6 && person3>person1 && person3>person2 && person3>person4 && person3>person5 && person3>person6 && person4>person1 && person4>person2 && person4>person3 && person4>person5 && person4>person6 && person5>person1 && person5>person2 && person5>person3 && person5>person4 && person5>person6 && person6>person1 && person6>person2 && person6>person3 && person6>person4 && person6>person5) ? person1 : person2 && person3 : person4 && person5 : person6;
}

int main()
{
cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";
person1();
char f;
cin>> f;
return 0;
}


This should work in theory, not compiled it yet :3 sorry, quote it if it fecks up :p

    
#include <iostream>
#include <conio.h>

int main()
{
using namespace std;

short cakes[6] = {0,0,0,0,0,0};
char answer;

short highest = 0;
short who = 0;
bool is_higher = false;

cout<<"Welcome to Pancake glutton\n";
cout<<"Enter a number to begin\n";

cin>>cakes[0];
cout<<"Person 1 ate : "<<cakes[0]<<"pancakes \n";

cin>>cakes[1];
cout<<"Person 2 ate : "<<cakes[1]<<"pancakes \n";

cin>>cakes[2];
cout<<"Person 3 ate : "<<cakes[2]<<"pancakes \n";

cin>>cakes[3];
cout<<"Person 4 ate : "<<cakes[3]<<"pancakes \n";

cin>>cakes[4];
cout<<"Person 5 ate : "<<cakes[4]<<"pancakes \n";

cin>>cakes[5];
cout<<"Person 6 ate : "<<cakes[5]<<"pancakes \n";

cout<<"Would you like to know who ate the most? (Y/N)";
cin>> answer;

if(toupper(answer) == 'Y'Winky Winky
{
for(short count = 0; count < 6; count++)
{
is_higher = false;

is_higher = (if(highest - cakes[count] < 1 ) ? true : false);

if(is_higher)
{
who = (count + 1);
highest = cakes[count];
}
}

cout<<"Person: "<<who<<" ate "<<highest<<" cakes which was the highest!";
}

cout<<"Press any key to continue . . .";
getch();

return 0;
}

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo