Jump to content

Anyone Know How to Program in C?


Recommended Posts

im trying to make basically a quiz

input and answer if correct move to the next question

my code is a follows:

#include <stdio.h>

#include <stdlib.h>

int main()

{

int a ;

char b ;

do {

printf("\nOpposite of 666: ");

scanf("%d" , &a);

if (a==999) {

printf("\nCorrect\n");

printf("Next Question\n");

printf("\n");

do {

printf("\nThe 13th letter of the alphabet is:");

scanf("%d" , &B);

if (b=='m') {

printf("\nCorrect\n");

printf("Next Question\n");

printf("\n");

}

else {

printf("\nIncorrect Learn Your Alphabet, or How to Count... ");

}

printf("\n");

} while(b=='a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

}

else {

printf("\nIncorrect");

}

printf("\n");

} while (a<1000);

}

now when enter m as the answer to the 13th letter of the alphabet it goes on a loop of "Incorrect Learn Your Alphabet, or How to Count... ");

i cant figure out why it does this

anyone know why?

btw if it wasnt apparent today was my first day in programming class. im just playing around with the program

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

To start with, you have 'm' in the if statement and the while statement, so even if you enter, m, it will ask the question again.

Fix that and then tell me what it does.

Current system:

1997 Blazer - (4) Customer Fi NEO subs with (8) American Bass Elite 2800.1s

Previous systems:

2000 Suburban - (4) BTL 15's and (4) IA 40.1's = 157.7 dB at 37 Hz.

1992 Astro Van - (6) BTL 15's and (6) IA 40.1's = 159.7 dB at 43 Hz.

Link to comment
Share on other sites

do {

printf("\nThe 13th letter of the alphabet is:");

scanf("%d" , &B);

I think that should be:

scanf("%c", &B);

Current system:

1997 Blazer - (4) Customer Fi NEO subs with (8) American Bass Elite 2800.1s

Previous systems:

2000 Suburban - (4) BTL 15's and (4) IA 40.1's = 157.7 dB at 37 Hz.

1992 Astro Van - (6) BTL 15's and (6) IA 40.1's = 159.7 dB at 43 Hz.

Link to comment
Share on other sites

still the same repeated sequence of failure

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

ok well with that %c change i can answer now

but after i answer the first question it gives me the second question and an automatic incorrect then brings up the question again for me to answer. then it works

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

Can you cut and paste what happens when you run the program?

Been a long time since I have programmed, and I learned C++.

Current system:

1997 Blazer - (4) Customer Fi NEO subs with (8) American Bass Elite 2800.1s

Previous systems:

2000 Suburban - (4) BTL 15's and (4) IA 40.1's = 157.7 dB at 37 Hz.

1992 Astro Van - (6) BTL 15's and (6) IA 40.1's = 159.7 dB at 43 Hz.

Link to comment
Share on other sites

program.jpg

all i did was type in 999 and hit enter

that is what came up

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

If you type m at that point, what does it do?

Current system:

1997 Blazer - (4) Customer Fi NEO subs with (8) American Bass Elite 2800.1s

Previous systems:

2000 Suburban - (4) BTL 15's and (4) IA 40.1's = 157.7 dB at 37 Hz.

1992 Astro Van - (6) BTL 15's and (6) IA 40.1's = 159.7 dB at 43 Hz.

Link to comment
Share on other sites

this

program1.jpg

which is basically right but with one minor error

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

It could be that you have a new line character in the buffer and it is reading it as the character the first time through. . .

What happens if you type an m at that point, and what happens if you type another character at that point?

Also note you can say if b != 'm' in that while statement instead of typing == and all of the letters of the alphabet.

Brian

Current system:

1997 Blazer - (4) Customer Fi NEO subs with (8) American Bass Elite 2800.1s

Previous systems:

2000 Suburban - (4) BTL 15's and (4) IA 40.1's = 157.7 dB at 37 Hz.

1992 Astro Van - (6) BTL 15's and (6) IA 40.1's = 159.7 dB at 43 Hz.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Who's Online   0 Members, 0 Anonymous, 1571 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...