Jump to content

Help: TurboC++

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
46 replies to this topic

#1
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
closed````````

Edited by Sallyqq, 20 August 2009 - 06:47 PM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Post your code. I think I know what you're getting at, but I'd like to see your code to make sure.
sudo rm -rf /

#3
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
for the game part is something like this. The Led blinks follow by the person entering the key then the program telling the person right/wrong. Sorry for the late reply. And thank for the reply.

Note: frequency of sound is not properly set yet.

Game2:
	{
	putc((char)8,stdprn);	//display LEDs 00100000
	delay(300);//300ms
	putc((char)0,stdprn);	//all LEDs off 00000000
	delay(300);//300ms
	putc((char)4,stdprn);	//display LEDs 00000001
	delay(300);//300ms
	putc((char)0,stdprn);	//all LEDs off 00000000
	delay(300);//300ms
	putc((char)8,stdprn);	//display LEDs 00010000
	delay(300);//300ms
	putc((char)0,stdprn);	//all LEDs off 00000000
	delay(300);//300ms

	printf("\nWhich 3 Leds light up? in sequence:");
	scanf("%s",&data);
	if (data=='C'||data=='c')  [COLOR="Magenta"] <--- first key right, how about telling the person second key and third is right?[/color] 
	{
	printf("\n you are so smart");
	{
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	nosound();

	}
	}
	else if (data!='C' || data!='c');            [COLOR="Magenta"]<-- first key wrong. how about telling the person second and third key wrong?[/COLOR]
	{                                                                                                              
	printf("\nYour memory fail!");                   
	{
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	sound(500);
	delay(500);
	nosound();
	}
	}

	printf("\nPress Y  to go next level, N to play again");
	printf("\nTo quit press Q");
	scanf("%s",&data);

Edited by Jaan, 15 August 2009 - 03:27 AM.
Please use code tags when you are posting your codes!


#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Please use code tags. Highlight your code and click on the little pound sign (#).

scanf("%s",&data);

Probably wrong. If data is a char, then it should be scanf("%c",&data). If data is a character array, then it should be scanf("%*s",data) or scanf("%*c",data) (note no ampersand; replace the asterisk with the length of your buffer.)

I would try this:
#include <string.h>
char data[4];

//get all three characters at once
scanf("%3c", data);

//check all three characters at once, ignoring case
if(strcasecmp(data,"abc") != 0) {
    //failed
}
else {
    //correct, proceed to next level
}

Edited by dargueta, 15 August 2009 - 09:16 AM.
Typo

sudo rm -rf /

#5
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
hey thank a lot! I will try that out. Super super coding.

#6
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
new help!!

Hello,


Have some other questions,

1) How to make a welcome message in the centre of the screen with it flashing and user can press any key to clear screen and proceed

2) You know the exact frequency of bingo and fail sound?

Example:

	sound(932+132);

	delay(500);

	sound(623+152);

	delay(500);

	sound(1223+223);

	delay(500);

	nosound();




Please thank. Thank a lot.

Cheers

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
That's highly dependent on the operating system. What library are you using for the sound? (At least tell us what .h file you're including.)
sudo rm -rf /

#8
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<math.h>


lol. The operating system, you will laugh. It is win 95. I have no idea why my school using that as a assignment.

Thank for replying so fast.

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
dos.h? Really? That's old. Surprised it works, I could never get it to when I tried. You probably have support for graphics.h, another ancient set of functions that don't work on current systems, but did just fine before. I'm not sure if you can use it on Windows systems, I've read conflicting things about it online, but it's worth a shot.
C Language Graphics Library Reference (Part 1)
C Language Graphics Library Reference (Part 2)
C Language Graphics Library Reference (Part 3)

Example Code (Scroll down a little bit further than halfway.)


If that doesn't work, there's some sample code for a more modern way here that you can look at. It's a bit dense, but I can understand most of it so I'll walk you through the code if you have trouble.
sudo rm -rf /

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
dos.h? Really? That's old. Surprised it works, I could never get it to when I tried. You probably have support for graphics.h, another ancient set of functions that don't work on current systems, but did just fine before. I'm not sure if you can use it on Windows systems, I've read conflicting things about it online, but it's worth a shot.
C Language Graphics Library Reference (Part 1)
C Language Graphics Library Reference (Part 2)
C Language Graphics Library Reference (Part 3)

Example Code (Scroll down a little bit further than halfway.)


If that doesn't work, there's some sample code for a more modern way here that you can look at. It's a bit dense, but I can understand most of it so I'll walk you through the code if you have trouble.
sudo rm -rf /

#11
Sallyqq

Sallyqq

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
lol. thank for that. I will read it tomorrow. Anyway, does the code above you gave yesterday works for win 95?

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
The strcasecmp thing? Should work on any operating system.
sudo rm -rf /