. ¦3<RELATIVISM
also does anybody know with the free function
. ¦3<RELATIVISM
after the use of malloc that is,is there any argument to select all varibles that used allocation?
int main(void)
{
int i, j, sum1, sum2, sum, card;
i = 0;
j = 0;
sum1 = 0;
sum2 = 0;
sum = 0;
long n, temp;
n = get_long("Number: ");
temp = n;
while (n > 0)
{
i = n%10;
n = n/100;
/ if (n/100 == 0)
{
card = n;
} /
sum1= sum1 + i;
}
i = 0;
n = temp/10;
while (n > 0)
{
i = n%10;
n = n/100;
i = i * 2;
if (i/10 > 0)
{
j = i%10;
i = i/10;
i = i + j;
}
sum2 = sum2 + i;
}
sum = sum1 + sum2;
if (sum%10 == 0 && n > (10^13))
{
/* if (card == 34 || card == 37)
{
printf("AMEX\n");
}
else if (card == 51 || card == 52 || card == 53 || card == 54 || card == 55)
{
printf("MASTERCARD\n");
}
else
{
printf("VISA\n");
}
*/
n = temp;
if (n % (10^13) == 34 || n % (10^13) == 37)
{
printf("AMEX\n");
}
else if (n % (10^14) <= 55 && n % (10^14) >=51)
{
printf("MASTERCARD\n");
}
else if (n % (10^12) == 4 || n % (10^15) == 4)
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
}
else
{
printf("INVALID\n");
}
}
. ¦3<RELATIVISM
http://paste.debian.net/
. ¦3<RELATIVISM
as for you question sorry i cannot help you Imstill learning as well
. ¦3<RELATIVISM
have you tried using cs50 help lib?
Hi, I'm having issues with pset3 , Plurality and check50 . Hi, I cannot find any problem with my code. It seems to do everything that is supposed to do.
Here's the code:
// cs50 2020
//PSET 3 Plurality
// takes count of user defined number of
//voters in election and returns result
//
// Max number of candidates
// Candidates have name and vote count
typedef struct
{
string name;
int votes;
}
candidate;
// Array of candidates
candidate candidates[MAX];
// Number of candidates
int candidate_count;
// Function prototypes
bool vote(string name);
void print_winner(void);
int main(int argc, string argv[])
{
// Check for invalid usage
if (argc < 2)
{
printf("Usage: plurality [candidate ...]\n");
return 1;
}
// Populate array of candidates
candidate_count = argc - 1;
//checks if candidate numberis above MAX
if (candidate_count > MAX)
{
printf("Maximum number of candidates is %i\n", MAX);
return 2;
}
//assigns location in array
for (int i = 0; i < candidate_count; i++)
{
candidates[i].name = argv[i + 1];
candidates[i].votes = 0;
}
int voter_count = get_int("Number of voters: ");
// Loop over all voters
for (int i = 0; i < voter_count; i++)
{
string name = get_string("Vote: ");
// Check for invalid vote
if (!vote(name))
{
printf("Invalid vote.\n");
}
}
// Display winner of election
print_winner();
}
// Update vote totals given a new vote
bool vote(string name)
{
for(int i = 0; i < candidate_count; i++)
{
if (strcmp(name,candidates[i].name) == 0)
{
candidates[i].votes++;
return true;
}
}
return false;
}
// find and store highest vote total
void print_winner(void)
{
int record = 0;
for (int i = 0; i < candidate_count; i++)
{
if ( candidates[i].votes > record)
{
record = candidates[i].votes;
}
}
//print winners
//printf("The winner is/are: \n");
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].votes == record)
{
printf("%s \n", candidates[i].name);
}
}
return;
}
I get these errors from check50
:( print_winner identifies Alice as winner of election
print_winner function did not print winner of election
:( print_winner identifies Bob as winner of election
print_winner function did not print winner of election
:( print_winner identifies Charlie as winner of election
print_winner function did not print winner of election
:( print_winner prints multiple winners in case of tie
print_winner function did not print both winners of election
:( print_winner prints all names when all candidates are tied
print_winner function did not print all three winners of election
Any help would be most appreciated
. ¦3<RELATIVISM
is a good, or bpa.st one or is also trusted
. ¦3<RELATIVISM
fuegopazzo (Gitter):
. ¦3<RELATIVISM
seach for that term
. ¦3<RELATIVISM
usually you change something and just ask for people to pull from your repositorie
. ¦3<RELATIVISM
I can be wrong though given I never submited it
. ¦3<RELATIVISM
there is also a package called submit50, which might be for that
. ¦3<RELATIVISM
Hopefully this helped cheers
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu/crt1.o: In function _start':
(.text+0x20): undefined reference to
main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<builtin>: recipe for target 'cash' failed
make: * [cash] Error 1