How can I improve this program? Am I doing good/bad practice? Why?

Hello everyone, this is my first post, and I would like to ask if my program can have an improvement in the way I wrote it. I know that functionally, this might not be the best, but I want to know if I can write any of this lines differently. Also I don’t know if I am using good practice of C. Please any comments will be helpful, I am a beginner to programming, I took my first programming class last semester.

This program is a quiz practice for a pre-calc. It will randomly ask you questions, and you will press enter to see the answer. You are not able to input the answer because I don’t know how to do that just get, but I will figure it out later. You can enter 1 to go to the next question or 0 to quit the program.

#include <stdio.h>

int qGenerator(int); //Prints the questions
void algoLoop(int); //

int main(int argc, char* argv[]){

const int NUMBER = 19; //Change this number if you want to add more questions.

srand(time(NULL)); //Generate the first "seed" value;

//Program introduction
printf("\n\nWelcome to \"New Quiz 1.0\"\n");
printf("This is an beta version to practice a few pre-calc topics\n\n");

algoLoop(NUMBER);

printf("Good luck my friend!\n");
printf("Bye!\n");

return 0;

}

int qGenerator(int rNumber)
{
int option;
char enter;

switch (rNumber)
{
case 1:

	printf("Express a FUNCTION NOTATION.\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: y = F(x)\n\n");
	break;

case 2:

	printf("Determinate if the followinf expression if a FUNCTION: x = y^2.\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: No, x = y^2 is not a function.\n\n");
	printf("If your answer was no, explain why.\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: This parabola is lying on its side.\nIt is symmetric about the line y = 2. It is not a function.\n\n");
	break;

case 3:

	printf("What is the range for quadratic?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: The range of a quadratic function is determinate by the vertx formula:\n x= -b / 2a. Then pass it in as F(-b/2a) = \"Value of Y\"\n\n");

	break;
case 4:

	printf("What is a vertical \"LINE TEST\".\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: The vertical line test is a vertical line to determine if a given relationship is a function.\nJust throw a vertical line. If the line pass\nthrough 2 points of the graph, its not a function\n\n");
	break;

case 5:

	printf("Express the quadratic formula?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: x = ( -b +-sqrt(b^2 -4 * a *c ) ) / ( 2 * a ). ");

	break;

case 6:

	printf("When a graph is symmectric to the X-Axis\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When a given point (x,y), (x,-y) exits.\nNote: Anything symmectric to X-Axis, is not a function!\n\n");
	break;

case 7:

	printf("When a graph is symmectric to the Y-Axis\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When a given point (x,y), (-x,y) exits.\n\n");
	break;

case 8:

	printf("When a graph is symmectric to the Origin?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When a given point (x,y), (-x,-y) exits.\n\n");
	break;

case 9:

	printf("When a function is INCREASING?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When F(x1) < F(x2).\n\n");
	break;

case 10:

	printf("When a function is DECREASING?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When F(x1) > F(x2).\n\n");
	break;

case 11:

	printf("When a function is EVEN?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When F(x) = - F(x).\nNote:It's also symmetric to the Y-Axis.\n\n");
	break;

case 12:

	printf("When a function is ODD?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When - F(x) = F(-x)\nNote: It's also symmetric to the Origin.\n\n");
	break;

case 13:

	printf("When a Vertical Translation occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = F(x) +- k.\n\n");
	break;

case 14:

	printf("When a Horizontal Translation occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = F( x +- h ).\n\n");
	break;

case 15:

	printf("When a Reflection over the X-Axis occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = - F(x).\n\n");
	break;

case 16:

	printf("When a Reflection over the Y-Axis occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = F(-x).\n\n");
	break;

case 17:

	printf("When a Reflection over the Origin occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = - F( -x ).\n\n");
	break;

case 18:

	printf("When a Vertical Strech/Compress occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = a * F(x). If absulote value of a > 1, is fatter.\n Or 0 <= a <1, it compress.\n\n");
	break;

case 19:

	printf("When a Horizontal Strech/Compress occurs?\n\n\n");
	printf("Press ENTER to see the answer.....\n\n");
	scanf_s("%c", &enter);
	printf("Answer: When y = F( c * x). If absulote value of c > 1, is compressed.\n Or 0 <= a <1, it strechs.\n\n");
	break;

default:

	printf("Something went wrong :( \n\n\n");

	break;
}

printf("NEXT = 1  QUIT = 0\n");
scanf_s("%d", &option);

return option;

}

void algoLoop(int NUMBER)
{
int rValue; //This is a generic number.
int keeper;
int qGBack; //Question generator int returned.
int counter = 0;

do
{
	counter++;
	for (int i = 0; i <= NUMBER; i++) //Scaling the random from 1 to 10.
	{
		do
		{
			
			rValue = (1 + rand() % NUMBER);
			keeper = rValue;


		} while (rValue != keeper);

	}

	printf("\n*** QUESTION NUMBER %d ***\n\n", counter);
	qGBack = qGenerator(rValue);

} while (qGBack == 1);

}

2 Likes

Well, you’ve done nothing wrong in your program and its not difficult to understand either ( maybe its because this is a simple code ). You’ve used indentation which is a good practice. You’ve also done a fairly good job with presentation so keep up the good work. Practice lots of programs and also ask for help whenever you need. I’m certain there will be many experts who will further help you.

With all this said, remember that this is only my opinion. Others may feel different but as far as I’m concerned, your program was easy to understand.

2 Likes

I think you’ve done fairly well in your coding as well.

2 Likes

@dsantosp12:
You kept the code very neat.
Follow the same and practice more
All the best!

2 Likes

Thank you very much for your response. Its good to know that I am doing good.

Thank you for your response. I appreciate it.

Thank you man.