Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 31-07-2006, 09:31 AM   #1 (permalink)
Console Junkie
 
aditya.shevade's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 991
Question How to add a timer and background music in a C program?


Hi

I am attaching a program that I wrote in C.

I want to display a timer on the screen which will run till main is called back.

The time should be displayed when the number guessed is correct. (With the final output).

Can I add background music to this program? Ias there any way? (I am not talking of the sound(frequency) function, a music in maybe midi format like we do in html).

Aditya

The attached file contains following code....

#include<stdlib.h>
#include<time.h>
main()
{
int w,x=0,r1,r2,r3,r4,r5,r6,r7,r8,y,nc=0,pc=0,quit;
clrscr();

y = input(w);

r2=(y-y%10)/10;
r4=(r2-r2%10)/10;
r6=(r4-r4%10)/10;
if(y%10==r2%10||y%10==r4%10||y%10==r6%10||r2%10==r 4%10||r2%10==r6%10||r4%10==r6%10)
{
main();
}
if(y<1000||y>10000)
{
main();
}
if(y>999&&y<10000)
{
while(x!=y)
{

printf("\n\n\t\tEnter Your Choise Between 999 And 10000\n\n\t\t\t\t");
scanf("%d",&x);
if(x<10000&&x>999)
{
pc=0;
nc=0;
if(x%10==y%10)
pc++;
r1=(x-x%10)/10;
r2=(y-y%10)/10;
if(r1%10==r2%10)
pc++;
r3=(r1-r1%10)/10;
r4=(r2-r2%10)/10;
if(r3%10==r4%10)
pc++;
r5=(r3-r3%10)/10;
r6=(r4-r4%10)/10;
if(r5%10==r6%10)
pc++;
if( y%10==x%10||y%10== r1%10||y%10== r3%10||y%10== r5%10)
nc++;
if(r2%10==x%10||r2%10==r1%10||r2%10==r3%10||r2%10= =r5%10)
nc++;
if(r4%10==x%10||r4%10==r1%10||r4%10==r3%10||r4%10= =r5%10)
nc++;
if(r6%10==x%10||r6%10==r1%10||r6%10==r3%10||r6%10= =r5%10)
nc++;

printf("\n\n\t\t%d - Positions Correct",pc);
printf("\n\n\t\t%d - Numbers Correct",nc);
if(pc==4&&nc==4)
{
clrscr();
printf("\n\n\n\n\n\t\tThe Number You Asked Me To Guess Is \n\n\n\n\n\t\t\t\t%d\n\n\n",x);
printf ("\n\n\t\tPress 1 to play again or any other key to quit\n\n\n\t\t");
scanf ("\n\n%d",&quit);
if (quit==1)
{
main();
}
else
{
thankyou();
}
}
}
if (x==-1)
{
clrscr();
printf("\n\n\n\t\tThank You For Playing The Game. Hope You Enjoyed.");
getch();
abort();
}
if (x<1000||x>10000)
printf("\n\t\tThe Number You Have To Guess Is Between 999 And 10000");
}
}
else
printf("\n\n\n\n\n\tThe Number You Want Me To Guess Should Be Between 999 And 10000\n\n\t\t\t\t");
getch();
return 0;
}

input(u)
{
printf("\n\n\n\n\n\n\t\tPlease Press Enter To Start The Game\n\n\n\t\tIf You Want To Quit The Game Before It Finishes\n\n\n\t\tThen Enter The Number -1.\n\n\n\n\t\t\t\t");
getch();
randomize();
u = rand() % 10000;
clrscr();

return (u);
}

thankyou()
{
clrscr();
printf ("\n\n\n\t\tThank You For Playing This Game. See You Next Time");
getch();
abort();
return 0;
}
Attached Files
File Type: zip BULLCOWS.zip (967 Bytes, 3 views)

Last edited by aditya.shevade; 31-07-2006 at 09:33 AM. Reason: To attach the file
aditya.shevade is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 31-07-2006, 11:59 AM   #2 (permalink)
Google Bot
 
Pathik's Avatar
 
Join Date: Aug 2005
Posts: 9,772
Default Re: How to add a timer and background music in a C program?

i m getting errors wen compiling it...
Pathik is offline  
Old 31-07-2006, 12:12 PM   #3 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: How to add a timer and background music in a C program?

@Aditya, if you want to add background music like MIDI/WAV/MP3 use VC++ or JAVA.
Regarding the Timer:
This is how you do it. Use a for loop & use the sleep function, start this in a separate
Thread. Adjust the value for sleep() function , so that it works perfectly. It should
display 1 sec, 2 sec to 59 sec, 1 min. and so on.
JGuru is offline  
Old 31-07-2006, 05:19 PM   #4 (permalink)
Console Junkie
 
aditya.shevade's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 991
Default Re: How to add a timer and background music in a C program?

@pathics

Which error are you getting?

Is it related to function declaration? If it is then please select the default type to c. ( I was having this problem when I saved the file as cpp in turboc and tried to compile it.).

Aditya
aditya.shevade is offline  
Old 31-07-2006, 05:27 PM   #5 (permalink)
Google Bot
 
Pathik's Avatar
 
Join Date: Aug 2005
Posts: 9,772
Default Re: How to add a timer and background music in a C program?

yup i saved it as c.. i got 2 errors... fucn decl..
Pathik is offline  
Old 31-07-2006, 07:50 PM   #6 (permalink)
Console Junkie
 
aditya.shevade's Avatar
 
Join Date: Jun 2006
Location: USA
Posts: 991
Default Re: How to add a timer and background music in a C program?

@pathiks

I have compiled the program and it's running it fine.

What is the message that you are getting?

I can't even give an exe file.

Aditya
aditya.shevade is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by icebags
- by clinton
- by ico
- by Charan
- by gohan89

Advertisement




All times are GMT +5.5. The time now is 11:08 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2