Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How do I make this code look and work better?

C++
 #include <stdio.h>
int main() {
  
  int life;
  int up;
  char chr;
  int n;
   // printf() displays the string inside quotation
printf("Welcome to snake.\n");

 printf("Hi, this is a game snake. The snake game is a simple game, basically, you have to move around, and eat food, without hitting yourself or the walls. Every time you eat, the snake grows bigger, making it harder.\n");
 printf("Before we start, How many lifes do you want?");
 printf("Enter a number:/t");
    scanf("%c",&chr);
printf("You chose %c ", chr);
printf("lives.\n");
printf("You have %c", chr);
printf("Lives\n");
if (char == null;)
{
printf("That is not a number\n");
}
return 0;
}


What I have tried:

I have been taking a break from this project
Posted
Updated 30-Mar-21 7:27am
v2
Comments
jeron1 30-Mar-21 10:42am    
By work, do you mean compile? I don't believe this code will.
ModerateHacker; 30-Mar-21 10:51am    
How does it not work?
jeron1 30-Mar-21 10:54am    
Does it compile?
ModerateHacker; 30-Mar-21 10:56am    
Yes
jeron1 30-Mar-21 11:06am    
Not with VS2017.

//what does this do?

if (char == null;)
{
printf("That is not a number\n");
}

Quote:
How do I make this code look and work better?


By taking advice and learning both basic programming and the C language. But since you will not do that, then there is very little chance that you will ever progress beyond this level of code. You still appear not to understand even the difference between char and int types, so you will not even get past the first few lines.

I apologise for sounding so negative but many of us have tried to help you over the last few months, but all to no avail.
 
Share this answer
 
Comments
CPallini 30-Mar-21 11:37am    
5.
Richard MacCutchan 30-Mar-21 11:45am    
Thank you, although stating (repeating) the obvious does not take much brain power.
OriginalGriff 30-Mar-21 11:50am    
5 from me as well, but the OP isn't going to listen ... :sigh:
Quote:
How do I make this code look and work better?

Your code does nothing but spitting a little text, the only improvement is presentation.

Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
C++
#include <stdio.h>
int main() {

	int life;
	int up;
	char chr;
	int n;
	// printf() displays the string inside quotation
	printf("Welcome to snake.\n");

	printf("Hi, this is a game snake. The snake game is a simple game, basically, you have to move around, and eat food, without hitting yourself or the walls. Every time you eat, the snake grows bigger, making it harder.\n");
	printf("Before we start, How many lifes do you want?");
	printf("Enter a number:/t");
	scanf("%c",&chr);
	printf("You chose %c ", chr);
	printf("lives.\n");
	printf("You have %c", chr);
	printf("Lives\n");
	if (char == null;)
	{
		printf("That is not a number\n");
	}
	return 0;
}

Indentation style - Wikipedia[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[^]
 
Share this answer
 
Comments
Richard MacCutchan 31-Mar-21 4:38am    
Waste of time. This guy never accepts what we suggest, just comes back with yet more pointless questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900