Thank you very much for your help. I have been working on this for about one week now. I really appreciate it. It works perfect now.
kbury
Posts
-
Bubblesort help -
Bubblesort helpI tried and changed to the code snippet that you had, this is what I get. 34 24 3 32 33 50 I need it to print for example LOTTO PICKS 3 8 12 21 22 39 and cannot seem to fix it to do that
-
Bubblesort helpI have tried this, prints out but will not generate random numbers
#include <stdio.h>
#include <stdlib.h>
#include<time.h>#define SIZE 6
#define MAX 53void printArray(int N[], int T);
void fillArray(int N[], int T);int main(void)
{
srand(time(NULL));int PICKED[] = {0,0,0,0,0,0};
fillArray(PICKED, SIZE);
printArray(PICKED, SIZE);return 0;
}void fillArray(int N[], int T)
{
for(int P=0; P<SIZE; P++)
{
N[P] = rand() % 52+1;for(int PASS=0; PASS<P; PASS++)
{
if(N[PASS] == N[P])
{
N[P] = (int) (rand()%52 +1);
P=-1;
}
}
}
}void printArray(int N[], int T)
{
int PASS, P;for(P=0; P<SIZE-1; P++) { for(PASS = P + 1; PASS < SIZE; PASS++) { if(N\[P\]>N\[PASS\]) { T = N\[PASS\]; N\[P\] = N\[PASS\]; N\[P\] = T; } } } printf("\\nLOTTO PICKS\\n\\n"); for(int P=0; P<SIZE; P++) printf("%d ", N\[P\]); printf("\\n");
}
-
Bubblesort helpCan someone please help me with my bubblesort. It does not seem to sort and also prints 3 times.
#include <stdio.h>
#include <stdlib.h>
#include<time.h>#define SIZE 6
#define MAX 53void printArray(int N[], int T);
void fillArray(int N[], int T);int main()
{
srand(time(NULL));int PICKED[] = {0,0,0,0,0,0};
fillArray(PICKED, SIZE);
printArray(PICKED, SIZE);return 0;
}void fillArray(int N[], int T)
{
for(int P=0; P<T; P++)
{
N[P] = (int) (rand()% 52+1);for(int y=0; y<P; y++)
{
if(N[y] == N[P])
{
N[P] = (int) (rand()%52 +1);
P=-1;
}
}
}
}void printArray(int N[], int T)
{ for(int P=0; P<SIZE-1; P++) { if(N\[P\]>N\[P+1\]) { int T = N\[P+1\]; N\[P+1\] = N\[P\]; N\[P\] = T;
printf("\nLOTTO PICKS\n");
for(int P=0; P<SIZE; P++){
printf("%d ", N[P]);printf("\n");
}}}}
-
Updated program-having a pointer errorThanks again. I will make a notation in regards to the braces. I did make some other changes because the execute did not look like the sample given. But now works perfectly.
-
Updated program-having a pointer errorThank you, That did fix the prob.
-
Updated program-having a pointer errorvoid Gen2Rand (int*r1p, int*r2p)
1. Error is undeclared identifier r2p 2. type error in argument 2 to 'Gen2Rand', found 'int' expected 'pointer to int' 3. possible usage of r1p and r2p before definition*r1p = r1; *r2p = r2;
1. Error is r1p and r2p is not a pointer. I met my instructor yesterday and he said that the prototypes were correct. So should I change the void Gen2Rand (int*r1, int*r2) -
Updated program-having a pointer errorCan someone please look at this and tell me what I am doing wrong with my pointer.
#include #include #define SENT 4 //"Quit" menu choice
/* Function Prototypes */
void DisplayMenu (void); int GetMenuChoice (void); void Gen2Rand (int\*r1, int\*r2); void DrillOneProb (int c, int r1, int r2);
/*============Mainline Procedures===============*/
int main (void)
{
int c; //Menu Choice (1-4)
int r1, //First Random Integer: 2-12 inclusive
r2; //Second Randon Integer: 2-12 inclusiveDisplayMenu(); c = GetMenuChoice(); while (c >= 1 && c < SENT) { Gen2Rand (&r1, &r2); DrillOneProb (c, r1,r2); DisplayMenu(); c = GetMenuChoice(); printf("Program Complete\\n");} return (0);
}
/*===========CHILD FUNCTIONS===============*/
/* Display Title and Menu */
void DisplayMenu (void)
{
printf("MENU OF OPERATIONS\n");
printf("1. Addition.\n");
printf("2. Subtraction.\n");
printf("3. Multiplication.\n");
printf("4. Quit.\n\n");}
/* Get Menu Choice */
int GetMenuChoice (void)
{ int c; do{ printf ("Enter the number of the operation to try (1-4):\\n"); scanf ("%d", &c); if (c<1 || c>SENT) printf("\\aInput value is out of range.\\n"); while (c < 1 || c > SENT); return (c); }
/* Generate and return 2 integers between 2-12 inclusive */
void Gen2Rand (int*r1p, int*r2p)
int r1; //First random number int r2; //Second random number r1 = 2 + rand() % 11; r2 = 2 + rand() % 11; \*r1p = r1; \*r2p = r2;
return (0);
}
/* Display two random numbers and ask user what the answer would be after the chosen operation*/
void DrillOneProb (int c, int r1, int r2)
{
int CorAns, //Correct Answer
Reply; // Users Replyswitch (c) { case 1: printf("+"); CorAns = r1 + r2; break; case 2: printf("-"); CorAns = r1 - r2; break; default: printf("x"); CorAns = r1 \* r2; break; } printf(" %d, ?", Reply); scanf ("%d", &Reply);
if
(Reply == CorAns)printf("Yes, that is correct. Good Job!"); else { printf("No, the correct answer is: %d", CorAns); printf("\\n\\n"); }
-
pointer and switchand what about the brace
-
pointer and switchI do not believe that has been in any of the chapters that we have read so far, but I will look again at the latest chapter because each assignment is associated with that chapter.
-
pointer and switchchange to printf("\nWhat is %d", *r1); (I already changed this)I figured that out. kbury wrote: r1 = 2 + rand() % 11; change to *r1 = 2 + rand() % 11; (This defineately fixed this. The above steps, however just fix compiler errors...I don't know if the semantic will be correct.
switch (c)
{ (states that this is illegal type pointer to int in switch expression.) case '1': printf("+"); CorAns = r1 + r2; (operands of + have illegal of 'pointer to int' and 'pointer to int') break;
-
pointer and switchI am stuck with this section of my code so far: error codes: expected int and got pointer to int and operands of = illegaltype pointer to int and int
/* Display two random numbers and ask user what the answer would be after the chosen operation*/
void DrillOneProb (int*c, int*r1, int*r2)
{
int CorAns, //Correct Answer
Reply; // Users Reply{ printf("\\nWhat is %d",r1); 1st error scanf("%d", r1); r1 = 2 + rand() % 11; 2nd error }
-
pointer and switchI am only trying to follow a flow chart given and it is very confusing. Thank you
-
pointer and switchThanks, I just changed and it fixed that part.
-
pointer and switchI am trying to write a program as a math tutor. Can someone look at this code. I keep getting errors on int and pointer as well as telling me the switch case has illegal pointer. Thanks, any advice would be greatful.
#include #include #define SENT 4 //"Quit" menu choice
/* Function Prototypes */
void DisplayMenu (void); void GetMenuChoice (void); void Gen2Rand (int\*r1, int\*r2); void DrillOneProb (int\*c, int\*r1, int\*r2);
/*============Mainline Procedures===============*/
int main (void)
{
int c; //Menu Choice (1-4)
int r1, //First Random Integer: 2-12 inclusive
r2; //Second Randon Integer: 2-12 inclusive}
/*===========CHILD FUNCTIONS===============*/
/* Display Title and Menu */
void DisplayMenu (void)
{ printf("MENU OF OPERATIONS\\n\\n"); printf("1. Addition.\\n"); printf("2. Subtraction.\\n"); printf("3. Multiplication.\\n"); printf("4. Quit.\\n\\n"); }
/* Get Menu Choice */
void GetMenuChoice (void)
{ int c; printf ("Enter the number of the operation to try (1-4):\\n"); scanf ("%d", &c); while (c<1 || c>SENT) printf("\\aInput value is out of range.\\n"); }
/* Generate and return 2 integers between 2-12 inclusive */
void Gen2Rand (int *r1p, int *r2p)
{ int c; c=0; if (c>=1 && c<SENT) int r1; // First random number int r2; //Second random number r1 = 2 + rand() %11; r2 = 2 + rand() %11; \*r1p = r1; \*r2p = r2; printf("Program complete\\n"); }
/* Display two random numbers and ask user what the answer would be after the chosen operation*/
void DrillOneProb (int *c, int *r1, int *r2)
{
int CorAns, //Correct Answer
Reply; // Users Reply{ printf("\\nWhat is %d", & r1); r1 = 2 + rand() % 11; } switch (c); { case '1': 1 = +; break; CorAns = r1 + r2; case '2': 2 = -; break; CorAns = r1 - r2; case '3': 3 = x; break; CorAns = r1 x r2; } printf("%d ? %d\\n", r2, Reply);
if
Reply = CorAns
{
printf("Yes, that is correct. Good Job!");
}else printf("No, the correct answer is: %d", CorAns); printf("\\n\\n");
return (c);
print\_menu(); //Print the menu option, and configure some needed things. return (0); //The end of our simple game.
-
numbers with boxesThanks for your help. I tried to code it just like you had in the 1st answer, but my compiler would not compile it.
-
numbers with boxesI am trying to stick to this flowchart given to me. Maybe I just do not understand it. In the flowchart it is only called where I have it in the code and after boxnum it is suppose to go back to col.
-
numbers with boxesanyways I changed the code and now it does this. Do i need to change the if boxnum statement?
printf ("\n\nThe numbering layout will be:\n");
while (r <= rows)
{ r = r + 1; printf ("\\n \\n");
while (c <= cols)
c = c + 1; printf (" %d |", boxnum); boxnum = boxnum + 1; if (boxnum <= 1); printf(" %d | ", boxnum++); } unit\_height = rows \* mbxhgt; unit\_width = cols \* mbxwid; printf ("\\nOverall height of mailbox unit: %d", unit\_height); printf ("\\nOverall width of mailbox unit: %d\\n", unit\_width);
return (0);
}Mailbox Layout Program How many rows of mailboxes will there be?4 How many columns of mailboxes will there be?5 The numbering layout will be: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Overall height of mailbox unit: 24 Overall width of mailbox unit: 20
-
numbers with boxesI am using the LCC Win 32 compiler and when I remove the semicolon away from if (boxnum <= 1); It does not print out the 6, 7, 8, 9 at all.
-
numbers with boxesI guess a gluton for punishment. I am new at this and am trying to learn from a online class, which seems to make this more difficult than I had expected.