Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Code block problem project!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sjl002
Master Cheater
Reputation: 0

Joined: 31 Aug 2013
Posts: 305

PostPosted: Fri Feb 02, 2018 10:23 am    Post subject: Code block problem project! Reply with quote

Hello my friends
I want to create a program in C language in the Code Block to do the bottom line:
Starting from number one, then we enter natural numbers in order. When we arrive at multiples of 5, we must enter H, if you enter a number or another, print a message.

Sorry for my bad writing. Very Happy
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Feb 02, 2018 11:08 am    Post subject: Reply with quote

so something like
Code:
1
2
3
4
H
6
7
8
9
H
11
12
13
14
15
<error you must enter H for multiples of 5!
H
17
<error expected 16!


?? sometimes examples of expected behavior is better than trying to explain the behavior, especially if you have to translate it from one language to another.
Back to top
View user's profile Send private message
sjl002
Master Cheater
Reputation: 0

Joined: 31 Aug 2013
Posts: 305

PostPosted: Fri Feb 02, 2018 11:24 am    Post subject: Reply with quote

Right.
you can help.
Code:

1
2
3
4
H
6
7
8
9
H
11
12
13
14
15
<error you must enter H for multiples of 5!
H
17
<error expected 16!

Yes.I want to write C code for this.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Feb 02, 2018 11:52 am    Post subject: Reply with quote

Then the basic scenario would probably be using scanf or gets to read the input as a string. You'd then have a variable holding the expected number (starting at 1), and check if that variable is a multiple of five (the mod/remainder operator % will be helpful there)
  • if it's a multiple of five, you'd check if the input was "H\n" (depending on how strict you wanted to be you could compare the first character to 'h' or 'H', use stricmp/strcasecmp, or strcmp). If it does not match, then you'd print an error
  • If it's not a multiple of five then you'd try to convert the input to a number, either with sscanf or atoi (stands for ASCII To Integer), if the conversion fails or the number is not equal to the expected number then you'd print an error
In any scenario that successfully matched the expected input you'd add 1 to the variable storing the expected value. Finally you'd have all of that inside a loop so that it reads the user's input again.


so something like

Code:
char input[]
int expected = 1
while true do
  scanf("%s", input)
  if expected mod 5 is 0 then
    if input is not 'h' then print("FAIL!") else expected++ end
  else
    int result = atoi(input)
    if result is not expected then print("FAIL!") else expected++
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Fri Feb 02, 2018 11:58 am    Post subject: Reply with quote

This really seems like a homework assignment OP should at least attempt before asking for an answer.

Post what code you have so far and others may help fix and/or improve it.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites