random number program

This is a discussion on random number program within the C Programming forums, part of the General Programming Boards category; hello i'm fairly new to C and theres this rather cruel program that my teacher has given me to solve. ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    random number program

    hello i'm fairly new to C and theres this rather cruel program that my teacher has given me to solve.

    it generates a x + y = ? equation with x and y being rather ridiculously large numbers and for some reason he made it so that if i don't calculate in 5 seconds, the program will shut down and the variables will be re-randomized.

    i'd love some help on this. i've tried rather futile attempts on creating another program with the vague idea of using main(int argc, char *argv) to open the program and attain its variables and auto calculate it, but then i don't know how a calculator works lol. i tried googling on how to scan the program but then it comes up with things that are probably not needed to solve this.. like dll injection or something o.O.

    thanks

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    It may be easier to help you if your explain your teacher's program a little more or provide us some code.

    So your teacher's program prints out "x + y =" and then you have five seconds to input the correct answer? And you need to create a new program that solves it or do you need to edit your teacher's program?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    unfortunately i have no access to the source code. yes it gives you 5 seconds to answer correctly or it resets and comes out with a new equation. im glad its always addition.
    yup i have to create a new program that solves it.

    thing is i tried making a sorta loop. i wrote program "a" to run the program that my teacher made and using srand/rand to generate my own random output with variables num1+num2. i used "num1=rand()%((999999-1)+1+1);". same with num2. i was wondering if "return num1+num2" would do anything even though i didn't use a function o_o. although this way i'd be waiting... quite a while. not that it worked properly anyway lol.
    trouble was that because after my teachers program is run, after it shows the equation it sleeps straight for about 5 seconds during which my program can't do anything else.

    apparently his previous student solved it by use of raw brain power. i envisioned the way numbers would have flown around inside the dudes mind o_o

    i run my teachers program "randomness" and it spits out 193929 + 124121 = ?
    if i type a wrong answer it gives me, "no!! lets study!".
    hmm. it seems to be always within 6 digit numbers.
    i asked him for a hint and he said "just hope for 1+1=?"
    Last edited by audgns7; 11-27-2011 at 09:12 PM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You still haven't said what it is you are actually supposed to do here, and what it has to do with C programming. You're just running his program, looking at the screen, and expected to type in the results in 5 seconds? Ok, so what's stopping you from grabbing a calculator and solving it and typing it in? What does this have to do with programming at all?


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I believe he wants a program to save his "raw brain power", but it will take more brain power to come up with a program to do it for him.

    And I bet the teacher would like him to learn that addition.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    What type of course is this and what exactly are you studying? This is starting to sound like an intro program for disassembly practice. Don't think we can talk about disassembly on here.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    lol what a dearie you are, Adak. you keeping in mind the equation isn't fixed? thanks anyway.

    well, what im doing here is asking how my teacher program could be solved? i'm at a loss hence why i am looking for answers. the problem is in c code, so i assume that has something to do with c programming.

    im studying information security.. maybe i am in the wrong place o_o?
    teacher told me clearly the solution to this can be made with another program.
    dont think it'll involve disassembling

    yeahh im sure there are guys out there that can solve this by using a calculator. i just lack the hand eye co-ordination to punch in the digits fast enough. besides that im sure the purpose of the problem wasn't to learn how to use the calculate with a speedy hand.

    annd if you start questioning the purpose of the question you could say that im supposed to do this on my own buuut i dont know where to look hmm.
    i've been googling for 3 days but i seem to be on the wrong track!
    course will move on without me solving this, but i just really wanna know lol

    much appreciation for helpful replies
    Last edited by audgns7; 11-27-2011 at 09:52 PM.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    If you don't have access to the source code, then the only reason it would matter that the program was written in C would be to tell you that it was written in a language that can have lots of security holes to exploit. It just seems to me to be a disassembly problem. Is there anyway you can upload the program so that we can get a better idea of what exactly is going on? Perhaps, we're simply misunderstanding the specifications that you've posted.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by audgns7 View Post
    lol what a dearie you are, Adak. you keeping in mind the equation isn't fixed? thanks anyway.

    well, what im doing here is asking how my teacher program could be solved? i'm at a loss hence why i am looking for answers. the problem is in c code, so i assume that has something to do with c programming.

    im studying information security.. maybe i am in the wrong place o_o?
    teacher told me clearly the solution to this can be made with another program.
    dont think it'll involve disassembling
    Redirect the random program's stdin and stdout through your program, trap the text as it comes through the redirect pipe, let your program read the screen text, solve the equation then provide it's own answer back through the redirect...

    Creating a Child Process with Redirected Input and Output
    How to redirect Standard Input/Output of an application - CodeProject
    How to spawn console processes with redirected standard handles

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    ah i'm sorry i can't upload the program. all of these problems are set up on his server and i have only read and run authority. hmm my apologies for not making this any easier

  11. #11
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    thank you CommonTater and failure67! time to read read read

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Kind of funny, but I had this impression you were a brain damaged vet in re-hab, and re-learning arithmetic. <ROFL!>

    Your problem is simplicity itself, *IF* your program is allowed to run.

    Code:
    int n1, n2, sum=0; 
    char ch;
    
    fscanf(stdin,"%d %ch %d",&n1, &ch &n2);  
    
    sum=n1 + n2;
    fprintf(stdout,"The sum is: %d\n",sum);
    Add in your stdio.h header and main(), and you should have a working program in jig time.

    You may need to adjust the spacing in the fscanf() format, depending on exactly how the numbers and the + are presented.

  13. #13
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    lolol thank you. i'll have to try to type more clearly. my essays get remarked on as being "too vague" o_o

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I wasn't talking about redirection using the command line... I meant redirecting the standard handles...

    Open Pelles C... see the "output" window at the bottom... like that...

  15. #15
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    hurrah it worked out somehow!

    thank you very kindly for your replies!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reliable Random Number Program
    By ShinigamiCooper in forum C Programming
    Replies: 11
    Last Post: 09-03-2010, 08:47 PM
  2. Random Number Generator Program...PLEASE HELP!!
    By girly_engineer in forum C++ Programming
    Replies: 17
    Last Post: 06-16-2010, 12:23 AM
  3. C++ program random number generator need help
    By catdieselpow in forum C++ Programming
    Replies: 15
    Last Post: 10-07-2007, 05:53 PM
  4. Replies: 2
    Last Post: 12-25-2003, 01:31 AM
  5. random number program
    By thatdude in forum C++ Programming
    Replies: 25
    Last Post: 11-13-2003, 09:52 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21