Oct 31, 2015 at 1:59am UTC
hello there, I need help implementing with a simple code
I am trying to generate multiple Different tickets, so far my code generates tickets but they are all the same, how do I change that, I would appreciate any help .
#include <iostream>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
using namespace std;
int main()
{
int min_ticket , max_ticket ;
int n1, n2, n3, n4, n5, n6;
cout << "Enter Minimum no. of ticket to be generated : ";
cin >> min_ticket;
cout << "Enter Maximum no. of ticket to be generated : ";
cin >> max_ticket;
int ticknum = min_ticket + rand() % (max_ticket - min_ticket);
cout << ticknum << endl;
//int n1, n2, n3, n4, n5, n6;
for (int c = 0; c < ticknum; c++)
{
n1 = 1 + (rand() % 47);
n2 = 1 + (rand() % 47);
n3 = 1 + (rand() % 47);
n4 = 1 + (rand() % 47);
n5 = 1 + (rand() % 47);
if (n1 != n2 && n1 != n3 && n1 != n4 && n1 != n5 &&
n2 != n3 && n2 != n4 && n2 != n5 &&
n3 != n4 && n3 != n5 && n4 != n5) {
break;
}
}
for (int i = 0; i < ticknum; i++)
{
n6 = 1 + (rand() % 27);
}
for (int i = 0; i < ticknum; i++)
{
cout << "Ticket " << n1 << " " << n2 << " " << n3 << " " << n4 << " " << n5 << " " << n6 << endl;
}
return 0;
}
Oct 31, 2015 at 3:53am UTC
.
Last edited on Oct 31, 2015 at 4:06am UTC
Oct 31, 2015 at 4:00am UTC
how do I use the code tags?
Oct 31, 2015 at 4:04am UTC
Don't double post and waste our time by duplicating effort
http://www.cplusplus.com/forum/general/177567/
Last edited on Oct 31, 2015 at 4:16am UTC
Oct 31, 2015 at 4:11am UTC
I am sorry but I am new here, I didn't mean to post it twice because I thought I posted my original question in the wrong forum and that's why no one has answered me, I apologize and thanks.
Oct 31, 2015 at 4:20am UTC
OK we all make mistakes. I suggest you use the other post where all the other work is to be seen. There is no danger of your posts not being seen.
Oct 31, 2015 at 4:26am UTC
thank you. how do I delete this post?
also can you show me how to use the code tags, I would truly I appreciate it.
Oct 31, 2015 at 4:34am UTC
Don't worry about it. I don't think u can. Go to your other site.
Code tags are shown as <> in the tool box on the right when you're typing up your post
Select the text u want and hit the <> button.
:)