im using <stdio.h> and <conio.h> only is there any solution so I can randomize result? I want to make a fortune cookie that randomize the reading.

i am not familiar with iostream and stdlib


thanks

Recommended Answers

All 13 Replies

there's no reason why you should be afraid of <stdlib.h>. it won't bite you. you should not use <conio.h> that library has been obsolete for 20 years. most modern compilers do not use it.

as to "how to randomize", here's the simple answer: if you want a random number from 1 to 'n',

int number;
number = rand() % n + 1;

there some are problems with this method, but you don't need to worry about them for now.

one thing, this will generate the same sequence of "random" numbers each time you run the program. if you want a different sequence of random numbers each time the program is run, you'll need to "seed" the number generator, using "srand"

I already gave you a solution in a C++ thread. Why do you keep cross-posting?

I already gave you a solution in a C++ thread. Why do you keep cross-posting?

i was trying to find code or solution without using stdlib.h , but i guess thats what i need to use, in order to make it work.
May I ask if Is it safe to download Turbo C in brothersoft.com... I'm afraid to do so because of possible virus that comes with it.
Sorry if i offend you or something.

>i was trying to find code or solution without using stdlib.h
Unless you need something stronger than rand, it's best to keep to the standard libraries. However, implementing your own random number generator is an entertaining exercise.

>May I ask if Is it safe to download Turbo C in brothersoft.com
If I say "NO! It's a virus!", will you forget about Turbo C and use a more up-to-date compiler? I'm not against lying if it benefits everyone. :D

commented: Liar! It is a trojan! :D +8
commented: Can't say you didn't try... +3

We used Turbo C in our programming and we need to do our project using Turbo C only. :(

We used Turbo C in our programming and we need to do our project using Turbo C only.

That's a lie. Your instructor is an incompetent dolt. If he says otherwise, send him here.

Do everyone a favor, especially yourself, and use a modern development environment such as code::blocks with the MinGW compiler.

anything you build using a modern compiler that complies with the C standard (such as the link above) , will work on your instructor's retarded choice of a 20-year-old dried turd of a compiler. the reverse is NOT true, however, so don't waste your time building garbage on a decrepit toy.

do it right.


.

commented: For a neverending anti-turbo-c campaign. +8
commented: "Beautiful" imagery +3

>we need to do our project using Turbo C only
Turbo C was/is reasonably conformant to C89. As long as you don't use silly TurboC-isms like conio.h or graphics.h and other non-standard features, code written on a modern compiler is highly likely to work on Turbo C.

>If he says otherwise, send him here.
That's an excellent idea, but I have yet to see it bear fruit. First and foremost, the instructor doesn't always have a say in the contents of the curriculum or the tools used. Second, what teacher is going to go to a forum to hear random people whine and flame? I wouldn't waste my time like that either if I were the OP's teacher. ;)

Second, what teacher is going to go to a forum to hear random people whine and flame?

because.... they have so much free time on their hands, since they're not researching new teaching methods or current industry trends?

eh, yeah ... okay ... i got nothing.

ok i'll use another way to program it even if he did not discuss it like the stdlib.h.... still using the turbo C though...

is there any site u recommend to download Turbo C that is safe, without any virus? please.
thanks. God bless the wise!

ok i'll use another way to program it even if he did not discuss it like the stdlib.h

<stdio.h> which you already use, is the STanDard Input and Output library header. it's a "standard", you see....

<stdlib.h> is the STanDard LIBrary. it's also "standard". Its the default library for darn near every C program in the world. So don't be scared. the fact that your professor is withholding it from you like it's some big secret, is even more evidence suggesting his incompetence.

<conio.h> is CONsole Input and Output. It's not standard, it's obsolete. you avoid it like the plague. or don't, and get the plague. doesn't matter to me, i won't ever have to work with you.

is there any site u recommend to download Turbo C that is safe, without any virus? please.
thanks. God bless the wise!

no, i refuse to do so on the grounds that it will violate my principles. and god forbid you go find it yourself.

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
int month,day,year;

clrscr();
printf(" Know your Zodiac Sign and have some Fortune Cookie\n\n");
printf(" Enter your Birth day (1-31):  ");
scanf("%d",&day);
printf("\n Enter your Birth month (1-12): ");
scanf("%d",&month);
printf("\n Enter birth year: ");
scanf("%d",&year);
if (month==3&&day>20||month==4&&day<21&&year>0)
	printf(" \n Your zodiac sign is ARIES");

if (month==4&&day>20||month==5&&day<21&&year>0)
	printf(" \n Your zodiac sign is TAURUS");

if (month==5&&day>20||month==6&&day<21&&year>0)
	printf(" \n Your zodiac sign is GEMINI");

if (month==6&&day>20||month==7&&day<23&&year>0)
	printf(" \n Your zodiac sign is CANCER");
if (month==7&&day>22||month==8&&day<22&&year>0)
	printf(" \n Your zodiac sign is LEO");
if (month==8&&day>21||month==9&&day<24&&year>0)
	printf(" \n Your zodiac sign is VIRGO");
if (month==9&&day>23||month==10&&day<24&&year>0)
	printf(" \n Your zodiac sign is LIBRA");
if (month==10&&day>23||month==11&&day<23&&year>0)
	printf(" \n Your zodiac sign is SCORPIO");
if (month==11&&day>22||month==12&&day<23&&year>0)
	printf(" \n Your zodiac sign is SAGITTARIUS");
if (month==12&&day>22||month==1&&day<21&&year>0)
	printf(" \n Your zodiac sign is CAPRICORN");
if (month==1&&day>20||month==2&&day<20&&year>0)
	printf(" \n Your zodiac sign is AQUARIUS");
if (month==2&&day>19||month==3&&day<21&&year>0)
	printf(" \n Your zodiac sign is PISCES");

if (month==0||month>=13)
	printf(" \n \t!Invalid Month!\n");
if (day==0||day>=32)
	printf(" \n\t !Invalid Day!");

getch();
}

this is the zodiac sign program, and now im finding ways to research about stdlib so i can insert and edit ways to get the fortune cookie random results.

it might not be a very good coding, but its working....
thank you for your replies, GB.

My teacher doesn't have the time to teach about this one, this 2nd sem is too short of a time.

doesn't have time to teach about <stdlib.h>? yet, will teach about <conio.h>?? i pity your class.

anyhow, what i don't have time for is looking at code that's been posted without code tags

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.