Tech Support banner

Status
Not open for further replies.
1 - 15 of 15 Posts

·
Banned
Joined
·
402 Posts
Discussion Starter #1
Hey i'm just getting into C programming, so here's my first try at a proper program, not smething that just says your name.

and the exe file and the source file is attached, if you want it or if you want to edit it.

well any ways here it is

Code:
#include<stdio.h>

int main()
{
    
    int Q1;
    int Q2;
    int Q3;
    int Q4;
    int Q5;
    int Q6;
    int Q7;
    int Q8;
    int Q9;
    int Q10;
    
    
    Q1 = 25;
    Q2 = 56;
    Q3 = 473;
    Q4 = 121;
    Q5 = 69;
    Q6 = 49;
    Q7 = 27;
    Q8 = 63;
    Q9 = 100;
    Q10 = 161;
    
 printf("Multiplication test © echo off productions.\n\n");
 printf("What is 5x5, then press enter: ");
 scanf("%d", &Q1);

 if ( Q1 == 25 ){
                 
 printf("\nWell done, Correct answer, Press enter to continue.");
 getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue.");
getch();
}
printf("\n\nWhat is 7x8, Then press enter: ");
scanf("%d", &Q1);

if ( Q2 == 56 ){
     printf("\nWell done, Correct answer, Press enter to continue.");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer, Press enter to continue");
          getch();
          }
          
          printf("\n\nWhat is 43x11, Then press enter: ");
          scanf("%d", &Q3);
          
          if ( Q3 = 473 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
     printf("\nSorry, Wrong answer, Press enter to continue");
     getch();
     }
printf("\n\nWhat is 11x11, then press enter: ");
scanf("%d", &Q4);

if ( Q4 == 121 ){
     printf("\nWell done, Correct answer, Press enter to continue.");
     getch();
     }
     else {
          printf("\nSorry, Wrong Answer, Press enter to continue.");
          getch();
          }
printf("\n\nWhat is 23x3, then press enter: ");
scanf("%d", &Q5);

if ( Q5 == 69 ){
     printf("\nWell done, Correct answer, Press enter to continue");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer, Press enter to continue.");
          getch();
          }
printf("\n\nWhat is 7x7, Then press enter: ");
scanf("%d", &Q6);

if ( Q6 == 49 ){
     printf("\nWell done, Correct answer, Press enter to continue");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer, Press enter to continue");
          getch();
          }
printf("\n\nWhat is 9x3, then press enter: ");
scanf("%d", &Q7);

if ( Q7 == 27 ){
     printf("\nWell done, Correct answer, Press enter to continue");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer, Press enter to continue");
          getch();
          }
printf("\n\nWhat is 9x7, then press enter: ");
scanf("%d", &Q8);

if ( Q8 == 63 ){
     printf("\nWell done, Correct answer, Press enter to continue");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer,Press enter to continue");
          getch();
          }
printf("\n\nWhat is 10x10, then press enter: ");
scanf("%d", &Q9);

if ( Q9 == 100 ){
     printf("\nWell done, Correct answer, Press enter to continue");
     getch();
     }
     else {
          printf("\nSorry, Wrong answer, Press enter to continue");
          getch();
          }
printf("\n\nThe Final Question, What is 23x7, then press enter: ");
scanf("%d", &Q10);

if ( Q10 == 161 ){
     printf("\nWell done, You have completed the game!!!!!, Press enter to exit.");
     getch();
     }
     else {
          printf("\nSorry Wrong answer, but, you have completed the game!!!!!, Pres enter to exit.");
          getch();
     }
}
hope you like it, download it, give it a try,

and plus, do not type in letters, or it'll confuse the program and it will stop responding.
 

Attachments

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Hello!

Very nice start! You have been given some excellent general advice in your other thread, but have a look at my output:

Code:
Multiplication test ® echo off productions.

What is 5x5, then press enter: 25

Well done, Correct answer, Press enter to continue.

What is 7x8, Then press enter: 56

Well done, Correct answer, Press enter to continue.

What is 43x11, Then press enter: 8787

Well done, Correct answer, Press enter to continue

What is 11x11, then press enter: 43

Sorry, Wrong Answer, Press enter to continue.

What is 23x3, then press enter: 342

Sorry, Wrong answer, Press enter to continue.

What is 7x7, Then press enter: 49

Well done, Correct answer, Press enter to continue

What is 9x3, then press enter: 8787

Sorry, Wrong answer, Press enter to continue

What is 9x7, then press enter: 56

Sorry, Wrong answer,Press enter to continue

What is 10x10, then press enter: 100

Well done, Correct answer, Press enter to continue

The Final Question, What is 23x7, then press enter: 161

Well done, You have completed the game!!!!!, Press enter to exit.
And then to prove the point still further:

Code:
Multiplication test ® echo off productions.

What is 5x5, then press enter: 555

Sorry, Wrong answer, Press enter to continue.

What is 7x8, Then press enter: 555

Well done, Correct answer, Press enter to continue.

What is 43x11, Then press enter: 555

Well done, Correct answer, Press enter to continue

What is 11x11, then press enter: 555

Sorry, Wrong Answer, Press enter to continue.

What is 23x3, then press enter: 555

Sorry, Wrong answer, Press enter to continue.

What is 7x7, Then press enter: 555

Sorry, Wrong answer, Press enter to continue

What is 9x3, then press enter: 555

Sorry, Wrong answer, Press enter to continue

What is 9x7, then press enter: 555

Sorry, Wrong answer,Press enter to continue

What is 10x10, then press enter: 555

Sorry, Wrong answer, Press enter to continue

The Final Question, What is 23x7, then press enter: 555

Sorry Wrong answer, but, you have completed the game!!!!!, Pres enter to exit.
See if you can fix that bug. If you need any help, just ask!

Good luck, and very well done!
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Hello!

No problem at all! We are here to help! However, it is best if you can find the error yourself, so you understand. One of the two bugs is here:

Code:
printf("\n\nWhat is 7x8, Then press enter: ");
scanf("%d", &Q1);
Don't worry if you still can't see it. Programming is difficult to start off with, and you are doing a fantastic job!

The best of luck!

Richard

Hint: Find this code snippet in your whole code, and read around it, but the bug is in one of those two lines :)
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
The other bug is here:

Code:
          if ( Q3 = 473 ){
This one is slightly easier, so this time tell me why this if statement always equals true, and always says "Correct".

Again, the best of luck!

Richard
 

·
Banned
Joined
·
402 Posts
Discussion Starter #6
got it
i replace this:
scanf("%d", &Q1");
with this:
scanf("%d", &Q2");
as question two is not question 1, duh!!

and for the second one i replaced this:
if ( Q3 = 473 ){
with this:
if ( Q3 == 473 ){
,

so here is the final code:

#include<stdio.h>
#include<conio.h>

int main()
{

int Q1;
int Q2;
int Q3;
int Q4;
int Q5;
int Q6;
int Q7;
int Q8;
int Q9;
int Q10;


Q1 = 25;
Q2 = 56;
Q3 = 473;
Q4 = 121;
Q5 = 69;
Q6 = 49;
Q7 = 27;
Q8 = 63;
Q9 = 100;
Q10 = 161;

printf("Multiplication test © echo off productions.\n\n");
printf("What is 5x5, then press enter: ");
scanf("%d", &Q1);

if ( Q1 == 25 ){

printf("\nWell done, Correct answer, Press enter to continue.");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue.");
getch();
}
printf("\n\nWhat is 7x8, Then press enter: ");
scanf("%d", &Q2);

if ( Q2 == 56 ){
printf("\nWell done, Correct answer, Press enter to continue.");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue");
getch();
}

printf("\n\nWhat is 43x11, Then press enter: ");
scanf("%d", &Q3);

if ( Q3 == 473 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue");
getch();
}
printf("\n\nWhat is 11x11, then press enter: ");
scanf("%d", &Q4);

if ( Q4 == 121 ){
printf("\nWell done, Correct answer, Press enter to continue.");
getch();
}
else {
printf("\nSorry, Wrong Answer, Press enter to continue.");
getch();
}
printf("\n\nWhat is 23x3, then press enter: ");
scanf("%d", &Q5);

if ( Q5 == 69 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue.");
getch();
}
printf("\n\nWhat is 7x7, Then press enter: ");
scanf("%d", &Q6);

if ( Q6 == 49 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue");
getch();
}
printf("\n\nWhat is 9x3, then press enter: ");
scanf("%d", &Q7);

if ( Q7 == 27 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue");
getch();
}
printf("\n\nWhat is 9x7, then press enter: ");
scanf("%d", &Q8);

if ( Q8 == 63 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer,Press enter to continue");
getch();
}
printf("\n\nWhat is 10x10, then press enter: ");
scanf("%d", &Q9);

if ( Q9 == 100 ){
printf("\nWell done, Correct answer, Press enter to continue");
getch();
}
else {
printf("\nSorry, Wrong answer, Press enter to continue");
getch();
}
printf("\n\nThe Final Question, What is 23x7, then press enter: ");
scanf("%d", &Q10);

if ( Q10 == 161 ){
printf("\nWell done, You have completed the game!!!!!, Press enter to exit.");
getch();
}
else {
printf("\nSorry Wrong answer, but, you have completed the game!!!!!, Pres enter to exit.");
getch();
}
}
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Excellent work! You are more than welcome! It is a really nice program! This brings back memories! I still have all of my very first programs from years ago!

Richard
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Hello!

This brings back memories! Sadly, some seem to have gone missing over the years. My infamous Dictionary program seems to have disappeared (I used the horrible GoTo, and got into scoping issues so that once in the Removal Mode, one had to re-start the application) but other than poor (extremely poor) coding, it was actually quite good. Maybe that should be your next project!

Ban Goto! Create a console application of languages and definitions. (ie: C#: Best language in the world!) Store them in a Dictionary. Add functions to modify and delete the keys and values. Save them to a text file for a nice restart. Get the idea? Just a thought. Certainly no need to do it.

Just dug out a game I made a little while ago in XNA. I have never been a games developer, and this was my very first taste. It is also very easy to make levels. Sadly, I became bored, and never finished it (making levels was boring, and I never made the high scores list or title. Why not give it a try? http://www.niemiro.co.uk/FileShare/setup.zip

What do you think? Not too bad for a first game! Graphics nabbed from royalty free sources.

Richard
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
And as you can see, Level coding is very simple:

Code:
            if (level == 1)
            {
                // Clear all Bad Guys ready for level
                ClearAll();

                // Set location of Level Exit (will vary between levels)
                LEPosition.X = 0;
                LEPosition.Y = 0;

                // Start Square Guy in middle of screen (always at the moment but may change for later levels)
                SGPosition.X = (graphics.PreferredBackBufferWidth / 2) - (SGTexture.Width / 2);
                SGPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (SGTexture.Height / 2);
            }
            else if (level == 2)
            {
                // Clear all Bad Guys ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = 0;
                LEPosition.Y = 0;

                // Square Guy
                SGPosition.X = (graphics.PreferredBackBufferWidth / 2) - (SGTexture.Width / 2);
                SGPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (SGTexture.Height / 2);

                // Set Location of Bad Guy
                BGPositions.Add(new Vector2(BGTexture.Width * 2, BGTexture.Height * 2));
            }
            else if (level == 3)
            {
                // Clear all Bad Guys ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = 0;
                LEPosition.Y = 0;

                // Square Guy
                SGPosition.X = (graphics.PreferredBackBufferWidth / 2) - (SGTexture.Width / 2);
                SGPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (SGTexture.Height / 2);

                // Add two Bad Guys
                BGPositions.Add(new Vector2(BGTexture.Width, 0));
                BGPositions.Add(new Vector2(0, BGTexture.Height * 3));

            }
            else if (level == 4)
            {
                // Clear all Bad Guys ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = 0;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Add three Bad Guys
                BGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - LETexture.Width, BGTexture.Height));
                BGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - (LETexture.Width * 4), 0));
                BGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - (LETexture.Width * 4), BGTexture.Height));
            }
            else if (level == 5)
            {
                // Clear all Bad Guys ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = 0;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Set Bad Guy move speed to 2
                BGMoveSpeed = 2;

                // Add moving Bad guy
                MBGPositions.Add(new Vector2((graphics.PreferredBackBufferWidth / 2) - (BGTexture.Width / 2), 0));

                //Add variables to MoveOnX and UpTo Lists
                MovingOnX.Add(false);
                UpTo.Add((graphics.PreferredBackBufferHeight / 2) - (BGTexture.Height / 2));
            }
            else if (level == 6)
            {
                // Clear all Bad Guys and rectangles ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = graphics.PreferredBackBufferHeight - LETexture.Height;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Set Bad Guy move speed to 4
                BGMoveSpeed = 4;

                // Add two moving Bad Guys
                MBGPositions.Add(new Vector2(0, BGTexture.Height * 3));
                MBGPositions.Add(new Vector2(0, BGTexture.Height * 4));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(true);
                MovingOnX.Add(true);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
            }
            else if (level == 7)
            {
                // Clear all Bad Guys and rectangles ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = graphics.PreferredBackBufferHeight - LETexture.Height;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Set Bad Guy move speed to 4
                BGMoveSpeed = 4;

                // Add two moving Bad Guys
                MBGPositions.Add(new Vector2(0, BGTexture.Height * 3));
                MBGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - BGTexture.Width, BGTexture.Height * 4));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(true);
                MovingOnX.Add(true);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
            }
            else if (level == 8)
            {
                // Clear all Bad Guys and rectangles ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = graphics.PreferredBackBufferHeight - LETexture.Height;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Set Bad Guy move speed to 4
                BGMoveSpeed = 4;

                // Add two moving Bad Guys
                MBGPositions.Add(new Vector2(0, BGTexture.Height * 3));
                MBGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - BGTexture.Width, BGTexture.Height * 4));
                MBGPositions.Add(new Vector2((graphics.PreferredBackBufferWidth / 2) - (BGTexture.Width / 2), 0));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(true);
                MovingOnX.Add(true);
                MovingOnX.Add(false);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
            }
            else if (level == 9)
            {
                // Clear all Bad Guys and rectangles ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = graphics.PreferredBackBufferHeight - LETexture.Height;

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = 0;

                // Holes
                HPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - HTexture.Width, 0));
                HPositions.Add(new Vector2(0, graphics.PreferredBackBufferHeight - HTexture.Height));

                // Set Bad Guy move speed to 4
                BGMoveSpeed = 4;

                // Add four moving Bad Guys
                MBGPositions.Add(new Vector2(0, BGTexture.Height * 3));
                MBGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - BGTexture.Width, BGTexture.Height * 4));
                MBGPositions.Add(new Vector2(graphics.PreferredBackBufferWidth / 2, 0));// - (BGTexture.Width / 2), 0));
                MBGPositions.Add(new Vector2((graphics.PreferredBackBufferWidth / 2) - BGTexture.Width, graphics.PreferredBackBufferHeight - BGTexture.Height));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(true);
                MovingOnX.Add(true);
                MovingOnX.Add(false);
                MovingOnX.Add(false);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferWidth - BGTexture.Width);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
            }
            else if (level == 10)
            {
                // Clear everything ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (LETexture.Height / 2);

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (SGTexture.Height / 2);

                // Set Bad Guy move speed to 4
                BGMoveSpeed = 4;

                // Add three moving Bad Guys
                MBGPositions.Add(new Vector2(BGTexture.Width * 3, 0));
                MBGPositions.Add(new Vector2(BGTexture.Width * 4, graphics.PreferredBackBufferHeight - BGTexture.Height));
                MBGPositions.Add(new Vector2(BGTexture.Width * 5, 0));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(false);
                MovingOnX.Add(false);
                MovingOnX.Add(false);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
            }
            else if (level == 11)
            {
                // Clear everything ready for level
                ClearAll();

                // Level Exit
                LEPosition.X = graphics.PreferredBackBufferWidth - LETexture.Width;
                LEPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (LETexture.Height / 2);

                // Square Guy
                SGPosition.X = 0;
                SGPosition.Y = (graphics.PreferredBackBufferHeight / 2) - (SGTexture.Height / 2);

                // Holes
                HPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - HTexture.Width, 0));
                HPositions.Add(new Vector2(graphics.PreferredBackBufferWidth - HTexture.Width, graphics.PreferredBackBufferHeight - HTexture.Height));

                // Set Bad Guy move speed to 5
                BGMoveSpeed = 5;

                // Add three moving Bad Guys
                MBGPositions.Add(new Vector2(BGTexture.Width * 3, 0));
                MBGPositions.Add(new Vector2(BGTexture.Width * 4, graphics.PreferredBackBufferHeight - BGTexture.Height));
                MBGPositions.Add(new Vector2(BGTexture.Width * 5, 0));

                // Assign values to MovingOnX and UpTo
                MovingOnX.Add(false);
                MovingOnX.Add(false);
                MovingOnX.Add(false);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
                UpTo.Add(graphics.PreferredBackBufferHeight - BGTexture.Height);
            }
            else
            {
                // This is when game moves to level not yet programmed - therefore no Bad Guys

                // Clear all Bad Guys ready for level
                ClearAll();
            }
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Did it actually work? It does have an uninstaller. It's hardly the next WoW, but it was alright to start off with!

EDIT: I send you an old version. It was missing the best two levels! :(
 

·
TSF Microsoft Support Team Emeritus
Joined
·
738 Posts
Hello!

Of course! I also made a new level! A level 12! I might actually go back and make it pixel perfect at some point. It now uses .net Framework 4.0 and XNA 4.0. Good things to have on your system. The installer should download and install .net if you don't already have it, but I don't know if it is perfect, yet. Same link, new file: http://www.niemiro.co.uk/FileShare/setup.zip

See what you think!

P.S.: There are two little "developmental shortcuts" on the numpad!
 
1 - 15 of 15 Posts
Status
Not open for further replies.
Top