Hi, i need help or advice on how to start a code i have to write. This is the details of the program with an example: http://www2.cs.uh.edu/~acl/cs1410/prog6.pdf
Any help or advice on how to go about this would be greatly appreciated.

Recommended Answers

All 8 Replies

You probably need to be more specific as to what you need to get any help.

Good advice if you're stuck is to turn of your screen and grab pen and paper and think it over until you know what you want to do. Then coding comes easier.

Get on with it! Deadline is on Monday! :P

yes i do! ok i have a question, how would you generate random upper and lower case characters (i.e. letter)?

You can use the rand function with the range of the ASCII characters you want and put the numbers into chars.

You can use the rand function with the range of the ASCII characters you want and put the numbers into chars.

could you show me an example of how you would write it out?

Ok, here's some links you should check out and below, a simple example.

Try it out, make changes, read the documentation and enjoy the endless possibilities it provides.
rand() function
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
srand() function (generates a random seed)
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
Time library from c where we can get the time_t time ( time_t * timer ); function
http://www.cplusplus.com/reference/clibrary/ctime/
ASCII codes:
http://es.wikipedia.org/wiki/ASCII

#include <iostream>
//ctime is used to set the random seed.
#include <ctime> 

int main(int argc, char** argv)
{
  using namespace std;
  /*Initializes de seed to use the current time
  so that the numbers are different each run 
  of the application*/
  srand((unsigned)time(NULL));
  
  /*Check the ASCII code values.
  Lowercase goes from a = 97-> z=122 
  Uppercase goes from A = 65 -> Z=90 */

  //rand() returns a number between 0 and RANDMAX
  
  //arbitrarily, I decided to show 40 random letters
  for(int iii=0;iii<40;iii++)
  {
    char letter = rand()%25 + 65;
    cout<<letter<<" ";
  }

  /*
  Exercise 1: change 65 to 'A' 
  Exercise 2: change 65 to 'a'
  3: Use a number as a seed (instead of the time(NULL) function) 
  and you'll always get the same succession of random numbers"
  4: Test and research 
  */
}

Good luck and remember, be specific when you ask for help and show what you have done so far.

http://www.catb.org/esr/faqs/smart-questions.html

commented: nice +1

thanks a lot! but how would you get random upper and lower case letters at once?
ex output: cIyXv

Think about it. It's not hard and there's quite a few ways to accomplish it.

Before, you wanted 25 possible consecutive ASCII codes.

Now you want 50 (in groups of 25 and 25 starting from 'A' 65 and 'a' 97.

i was thinking maybe

char letter = rand()% 25 + 65 && rand% 25 + 97;

but i get smiley faces

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.