13 Replies - 4492 Views - Last Post: 29 June 2012 - 06:30 PM Rate Topic: -----

#1 timotz  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 01-April 12

a program i made in my first year of college xD

Posted 12 April 2012 - 01:30 AM

#include<stdio.h>
#include<conio.h>
#include<math.h>
void again(char choice);
void main()
{
int a,b,c, ctr;
float d,r1,r2, f1, f2, x, y, z, m, n, mn, ff1, ff2, add_my_nx;
char choice;
clrscr();
textcolor(YELLOW);
gotoxy(15, 7);printf("ENTER THE VALUE OF A,B,C TO FORM THE QUADRATIC EQUATION");
gotoxy(38, 9);printf("ax%c%cbx%cc ", 253, 241, 241);
gotoxy(5, 11);printf("a=");
scanf("%d",&a);
gotoxy(40, 11);printf("b=");
scanf("%d",&B)/>;
gotoxy(65, 11);printf("c=");
scanf("%d",&c);
gotoxy(33, 13);printf("The equation is: ");
gotoxy(38, 14);
if(a !=1){
gotoxy(36, 14);
if(b>0 && c>0)
printf("%dx%c+%dx+%d", a, 253, b, c);
else if(b>0 && c<0)
printf("%dx%c+%dx%d", a, 253, b, c);
else if(b<0 && c>0)
printf("%dx%c%dx+%d", a, 253, b, c);
else if(b<0 && c<0)
printf("%dx%c%dx%d", a, 253, b, c);
gotoxy(35, 16);}

if(a==1)
if(b>0 && c>0)
printf("x%c+%dx+%d", 253, b, c);
else if(b>0 && c<0)
printf("x%c+%dx%d", 253, b, c);
else if(b<0 && c>0)
printf("x%c%dx+%d", 253, b, c);
else if(b<0 && c<0)
printf("x%c%dx%d", 253, b, c);
gotoxy(35, 16);

if(a<=0)
printf("The Equation is unfactorable...");

else if(a==1)

{
d=(b*B)/>-4*a*c;
r1=((-B)/>+sqrt(d))/(2*a);
r2=((-B)/>-sqrt(d))/(2*a);
gotoxy(30, 15);printf("Factoring the Equation.");delay(9999999);
gotoxy(53, 15);printf(".");delay(9999999);
gotoxy(54, 15);printf(".\a");delay(9999999);
gotoxy(35, 16);
	if(sqrt(d)<0)
		printf("NO REAL ROOT EXISTS:");
	else if(r1<0 && r2<0)
	{
	printf("(x+%.0f)(x+%.0f)",fabs(r1), fabs(r2));
	}
	else if(r1<0 && r2>0)
	{
	printf("(x+.0f)(x&.0f)", r1, fabs(r2));
	}
	else if(r1>0 && r2<0)
	{
	printf("(x-%.0f)(x+%.0f)", r1, fabs(r2));
	}
	else if(r1>0 && r2>0)
	{
	printf("(x-%.0f)(x-%.0f)", r1, r2);
	}
}
else if (a>1)
{ctr=0;
for(m=-500; m<500;)
	{/*m*/
		n=-500;
			for(n=-500; n<500; m*n !=a)
				{/*n*/
				mn = m*n;
				if(mn != a)
				n++;
				else if (mn == a)
					{/*if*/
						x=-500;
						for(x=-500; x<500;)
						{/*x*/
								y=-500;
								for(y=-500; y<500;)
								{/*y*/
									z= x*y;
									add_my_nx= (m*y)+(n*x);
									if(ctr==3)
									{break;}
									if(z != c)
									y++;
									else if(z == c && add_my_nx==B)/>
										{
										if(m<0)
										ff1=fabs(m);
										else if(m>0)
										ff1=-m;
										if(n<0)
										ff2=fabs(n);
										else if(n>0)
										ff2=-n;
										if(x<0)
										f1=fabs(x);
										else if(x>0)
										f1=-x;
										if(y<0)
										f2=fabs(y);
										else if(y>0)
										f2=-y;
										ctr++;
										}
								else
								y++;
								}/*end y*/
						if(z !=B)/>
						x++;
						}/*end x*/


					}/*end if*/

				if(mn == a && z!=B)/>
				n++;
				}/*end n*/
	m++;
	}/*end m*/
gotoxy(30, 15);printf("Factoring the Equation.");delay(999999999);
gotoxy(53, 15);printf(".");delay(999999999);
gotoxy(54, 15);printf(".\a");delay(999999999);
gotoxy(35, 16);
if(ff2==1)
if(f1>0 && f2>0)
printf("(%.0fx+%.0f) (x+%.0f)", ff1, f1 , f2);
else if(f1>0 && f2<0)
printf("(%.0fx+%.0f)(x%.0f)", ff1, f1, f2);
else if(f1<0 && f2>0)
printf("(%.0fx%.0f)(x+%.0f)", ff1, f1, f2);
else if(f1<0 && f2>0)
printf("(%.0fx%.0f)(x%.0f)", ff1, f1, f2);

if(ff2 !=1)
if(f1>0 && f2>0)
printf("(%.0fx+%.0f) (%.0fx+%.0f)", ff1, f1 ,ff2, f2);
else if(f1>0 && f2<0)
printf("(%.0fx+%.0f)(%.0fx%.0f)", ff1, f1, ff2, f2);
else if(f1<0 && f2>0)
printf("(%.0fx%.0f)(%.0fx+%.0f)", ff1, f1, ff2, f2);
else if(f1<0 && f2>0)
printf("(%.0fx%.0f)(%.0fx%.0f)", ff1, f1, ff2, f2);
}
again(choice);
}

void again(char choice)
{
gotoxy(20, 18);printf("Would you like to enter another equation?");
gotoxy(39, 19);printf("Y/N");
gotoxy(40, 20);scanf("%s", &choice);
if(choice== 'y')
main();
else if(choice == 'n')
{clrscr();
gotoxy(30, 12);printf("THANK YOU! GOODBYE!");
delay(99999999);
exit();}
else if(choice != 'y' || choice != 'n')
{gotoxy(30, 21);printf("Enter a valid option...");
again(choice);}
}



first of all: i'm kinda new in the forums and YES I KNOW HOW STUPID IT(the "code") LOOKS!


I didnt really care for readable code back then. I just wanted the thing to run correctly. I dont do that anymore(not as much xD) just so everyone knows! i did this in Turbo C 2.01 (they still teach it at school for 1st years. yes i know right?). what makes me laugh is the part with the super long indentions and the comments that i used so the curly braces will be less confusing. yea try to look at the code and get some lulz xD

Is This A Good Question/Topic? 2
  • +

Replies To: a program i made in my first year of college xD

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: a program i made in my first year of college xD

Posted 17 April 2012 - 09:57 AM

If you remove the line breaks and unnecessary spaces it could pass as obfuscated code.
Was This Post Helpful? 0
  • +
  • -

#3 The_Programmer-  Icon User is offline

  • Death Scythe
  • member icon

Reputation: 24
  • View blog
  • Posts: 593
  • Joined: 24-October 11

Re: a program i made in my first year of college xD

Posted 17 April 2012 - 01:32 PM

Sometimes when I make programs in Java, I will make the most unreadable and unorganized code when I first make the program but when I am done and it runs great, I will choose better variable names and make the code perform better.
Was This Post Helpful? 3
  • +
  • -

#4 timotz  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 01-April 12

Re: a program i made in my first year of college xD

Posted 17 April 2012 - 05:07 PM

after doing that program i was like "Good thing i'll never have to look at that thing again." it took a helluva time to debug it.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7804
  • View blog
  • Posts: 13,198
  • Joined: 19-March 11

Re: a program i made in my first year of college xD

Posted 23 April 2012 - 09:20 AM

View PostThe_Programmer-, on 17 April 2012 - 03:32 PM, said:

Sometimes when I make programs in Java, I will make the most unreadable and unorganized code when I first make the program but when I am done and it runs great, I will choose better variable names and make the code perform better.



I used to do that. Then I figured out it was easier to do it right the first time.

Quote

after doing that program i was like "Good thing i'll never have to look at that thing again."


Not least because of this reaction

This post has been edited by jon.kiparsky: 23 April 2012 - 09:20 AM

Was This Post Helpful? 3
  • +
  • -

#6 timkd127  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 74
  • Joined: 27-February 10

Re: a program i made in my first year of college xD

Posted 10 May 2012 - 08:13 AM

I feel like code is never completely neat and clean on through first pass of developing it.
Was This Post Helpful? 0
  • +
  • -

#7 ConBon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 21-October 11

Re: a program i made in my first year of college xD

Posted 13 May 2012 - 03:17 PM

When doing group work in uni, I tend to crack up when my team mates fail to indent! Then I go all :gun_bandana: on their asses!
Was This Post Helpful? 0
  • +
  • -

#8 timotz  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 01-April 12

Re: a program i made in my first year of college xD

Posted 13 May 2012 - 07:18 PM

View PostConBon, on 13 May 2012 - 03:17 PM, said:

When doing group work in uni, I tend to crack up when my team mates fail to indent! Then I go all :gun_bandana: on their asses!

i know that feel bro cheers
Was This Post Helpful? 0
  • +
  • -

#9 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: a program i made in my first year of college xD

Posted 21 May 2012 - 07:38 PM

For whatever reason, when I was a beginner with C++, I used to create these insanely nested "for loop" structures (line 79). Perhaps this is a common thing?

This post has been edited by Aphex19: 21 May 2012 - 07:38 PM

Was This Post Helpful? 0
  • +
  • -

#10 totgeburt  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 227
  • Joined: 03-August 11

Re: a program i made in my first year of college xD

Posted 31 May 2012 - 05:41 PM

View PostAphex19, on 22 May 2012 - 02:38 AM, said:

For whatever reason, when I was a beginner with C++, I used to create these insanely nested "for loop" structures (line 79). Perhaps this is a common thing?


I just got out of that phase haha.
Was This Post Helpful? 0
  • +
  • -

#11 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: a program i made in my first year of college xD

Posted 07 June 2012 - 01:49 AM

Oh, god. Kill it with fire.
Was This Post Helpful? 0
  • +
  • -

#12 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: a program i made in my first year of college xD

Posted 12 June 2012 - 09:09 PM

View PostThe_Programmer-, on 17 April 2012 - 03:32 PM, said:

Sometimes when I make programs in Java, I will make the most unreadable and unorganized code when I first make the program but when I am done and it runs great, I will choose better variable names and make the code perform better.

I never could do that, because when I'm done I have no clue why it works.
Was This Post Helpful? 1
  • +
  • -

#13 Lionheart Richard King  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-June 12

Re: a program i made in my first year of college xD

Posted 25 June 2012 - 05:50 PM

looks fine to me.
Was This Post Helpful? 0
  • +
  • -

#14 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: a program i made in my first year of college xD

Posted 29 June 2012 - 06:30 PM

Now that you are older and wiser, you should try refactoring it to see how you have improved.

Considering the gotoxy() function is Borland specific, you're going to have to implement your own it seems.

/* ConsoleFunctions.h */

#ifndef __WINAPI_CONSOLE_WRAPPER_H
#define __WINAPI_CONSOLE_WRAPPER_H
                              
void gotoxy (int x, int y);
void clrscr (void);

#endif /* __WINAPI_CONSOLE_WRAPPER_H */



/* ConsoleFunctions.c */
#include "ConsoleFunctions.h"                      
#include <windows.h>
   
void gotoxy(int x, int y)
{
  static HANDLE hStdout = NULL;
  COORD coord;

  coord.X = x;
  coord.Y = y;

  if(!hStdout)
  {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  }
  
  SetConsoleCursorPosition(hStdout,coord);
}
   
void clrscr(void)
{
  static HANDLE hStdout = NULL;      
  static CONSOLE_SCREEN_BUFFER_INFO csbi;
  const COORD startCoords = {0,0};   
  DWORD dummy;
  
  if(!hStdout)               
  {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hStdout,&csbi);
  }
  
  FillConsoleOutputCharacter(hStdout,
                             ' ',
                             csbi.dwSize.X * csbi.dwSize.Y,
                             startCoords,
                             &dummy);    
  gotoxy(0,0);
}



(Code pulled from website)

If you've kept up on your C, you might be amazed at how much you can do to this. One thing I noticed is that you do not define the variable "B" anywhere.

Anyway, give it a shot and see what happens.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1