DIGIT-ARC read-only archive · snapshot: July 23, 2026

Turbo C/C++ and other junk compilers help, discussions and queries here

433 posts · originally from https://geek.digit.in/community/threads/turbo-c-c-and-other-junk-compilers-help-discussions-and-queries-here.136185/

C
c4u Original post #1
Nov 28, 2003 at 2:38 PM
Use this thread for Turbo C/C++ and other junk compilers discussions and queries.

Some tips:
1. Do not use this thread for general C/C++ queries.
2. Do not crap other threads with junk queries involving this junk compiler and non-standard antiquated code. Such threads will be deleted or merged here.
3. Don't ask for download fof this junk compiler in question, it's a proprietary software and users cannot share links of its download since that would be illegal.
4. Don't ask for projects or anything like that as that posts would be deleted, the old posts remain as an example.
S
Oct 11, 2004 at 11:06 PM
C++ project

Hi guys...i am desprately in need of a project in turbo c++ ver. 1...iam in class 12th and i dont wanna mess it up...if any of you has some kind of a project(without use of graphics) then please send it to me il be grateful...
D
Oct 11, 2004 at 11:17 PM
Hey give me ur mail id i'll send u one.
W
Oct 12, 2004 at 7:13 PM
chk out *www.funducode.com/.. u ca get many project ideas there
alib_i
alib_i #5
Oct 12, 2004 at 7:36 PM
project??

simulate the working of a metal-hydride reactor
by Numerical Analysis using explicit scheme on Finite Element Method
in Forward in Time and Space Algorithm

how abt that for a project ??

dont get psyched up... i was just joking :) :)
its my project actually
S
Oct 12, 2004 at 10:42 PM
C++ PROJECT

hi again...thanks a million for your replies...my email id is sahil_blues@hotmail.com ...if you people have any kind of projects(i.e. c++ programs) then please do send me...
whoopy_whale
Oct 14, 2004 at 1:40 PM
Free Codes available....

Hey man,
visit planetsourcecode
You will get plenty of source codes for free.A lot of categories are there.
codeguru is also good.
sujithtom
Oct 15, 2004 at 10:18 PM
What kind of project do you want????
S
Oct 16, 2004 at 10:44 PM
C++ PROJECT

i looking for a c++ program which can include topics upto pointers(including)...basically projects involving data management using files and stuff...
A
amitsaudy #11
Oct 17, 2004 at 3:49 AM
Gimme a basic idea of what u want the application to do.
A brief descp. any ideas.
Ill do the coding for you if possible.
Its Sunday.
S
Oct 18, 2004 at 11:27 PM
C++ PROJECT

i need to basically make a database of any thing like hotels,banking, airline tickets, cars in which we can put different specifications...after dat lil bit of manipulation of the entered data like calculation of interest in banking or fares in the airline thing...i am told for a min. use of graphics...only boxes ,text colors,background colors are allowed...
W
Oct 19, 2004 at 1:22 AM
how abt a car details or showroom.. or simulation of account handling in banks
S
Oct 19, 2004 at 10:48 PM
dat'll be perfect...but please ensure dat you dont make it too advanced kinds...thanks
U
ujjwal #15
Oct 19, 2004 at 11:09 PM
Asking for ideas is ok ... but you expect someone to do the whole project work for you? :roll:
S
Oct 19, 2004 at 11:32 PM
not exactly...if someone does make it for me i wouldn't mind fcourse...but if someone has an older one lying can very well give it to me...
W
Oct 20, 2004 at 10:36 PM
hmm.. u want the grapes. even without making a jump for it.. well i could hav said more.. ut as u r in 12th u already hav much to thnk abt .. si cut some slack this time.. but asking for help is somethng .. and getting everythng done for free is somethng else.. i thnk u r form a science backgrnd.. so my suggestion is if u wanna succeed in this field.. strat putting ur efforts.. instead of asking for someone elses
Who
Who #18
Mar 14, 2005 at 6:16 PM
Turbo C/C++ and other junk compilers discussions and queries here

Turbo C++ sucks.
N
Jul 13, 2005 at 4:23 PM
can any1 give me turbo c and c++

can any1 give me turbo c and c++ its urgent
kalpik
kalpik #20
Jul 13, 2005 at 4:53 PM
Just do a google for "turboc" and u'll get plenty of results!
Choto Cheeta
Jul 13, 2005 at 5:03 PM
r those compailers Free??

humm... may b not as Softmart is selling them....
Choto Cheeta
Jul 13, 2005 at 5:10 PM
humm....

is Turbo C++ is deferent that Borland Turbo C++...

so if the software is not Free or for Trial Use.... then dose the forum rule allow u to asking....

but hey mods what if he asking some one to b his friend... then present him one software....

lol....

:lol: :lol: :lol: :twisted: :twisted: :twisted:
S
Jul 13, 2005 at 8:17 PM
I suggest you one thing. Never go for Software piracy. Borland Turbo C 3 or any version with the EDITOR is not free. But do one thing. You can download Borland C++ Builder from www.borland.com. Just go to the downloads section and you will find your command line compiler. Download that. It's about 8.9 MB in size. It's also free to download. You'll have to register with Borland site first. Registration is also free. Moreover, how to configure the compiler with the command line is also very easy. Just search in google and you'll find plenty of help. If you are unable, then post your message again.
eagle_y2j
eagle_y2j #24
Jul 14, 2005 at 2:46 PM
I can plz contact me over my email
Maverick340
Jul 14, 2005 at 10:24 PM
Try for Turbo C++ 4.3 plus..Its GUI version and verry good
I have the *evil word* version of it and it ws worth it..
(the damn fool sold it at a high price!!!!)
C
Jul 15, 2005 at 9:48 AM
great. so how do u get this gui version. some download time or filesize! and which format we download the package.

and does it also work on serail nos. crackin method or it has entire package itself.
drgrudge
drgrudge #27
Jul 15, 2005 at 10:38 AM
@ nareshwithu:
I have watching this thread.. see all we see is members suggesting some thing and saying that it's not a freeware and saying wht *other evil* ways to get the same.
So I am closing this thread, in case some one got to suggest anything regarding this plz PM me or any other mods, we shall reopen this thread.

@ mods,
This thread was reported for 2 times (maybe more but i dint get those reports) , incase if anyone wants to reopen , plz do so.

Thread locked
S
saptak #28
Aug 27, 2005 at 1:05 AM
comin out of Turbo c++

Doods
Turbo C++ is acting funny!!!
I Alt-Xed it and i see nuttin but a black screen. Makes me do a :x restart every time.... altho when i Alt-tab it, i still see all Black but am able to Alt-tab again to turbo
Wat d hell is goin on???
Thor
Thor #29
Aug 27, 2005 at 2:49 AM
u using Win 98? or Xp?If using 98 get XP. Get a diff download og TC++. Never encountered any like urs. Sorry can't be of much help. :(
q3_abhi
q3_abhi #30
Aug 27, 2005 at 6:16 AM
Install the C++ again n then see if the problem persists.
escape7
escape7 #31
Aug 27, 2005 at 11:13 AM
reinstall C++, i had tha same problem...after re installation i faced no problems.
The Incredible
Sep 15, 2005 at 3:31 PM
C++ Programming

Hi!

Do any 1 of u is having knowledge of C++ Programming.

I'm in 9th class and our computer teacher hasn't taught us anything n after 2 weeks my exams r going to held.

They have given us 2 sheets of question bank with different type of programmes to b made. so if possible plz help me. or if u know abt any site which can solve such programmes so plz tell.

BTW i've tried cprogramming.com provided by digit in three incredibly useful sites sectiond but didn't found anything helpful.

Here's sum of programmes which i'm unable to make.

Question Bank

General Type:-

7. if a five digit number is entered thru keyboard then write a programm to reverse da number(e.g., 12345 reverse 54321)

10. Write a program 2 find da compound interest for a given principal, rate of interest and no. of years.

Plz kindly help me.

Bye.

Anindya Srivastava
Choto Cheeta
Sep 15, 2005 at 3:52 PM
lol... mate... 9th std with C++... we r learning this same thing in our college...

any way...

The Incredible said:
7. if a five digit number is entered thru keyboard then write a programm to reverse da number(e.g., 12345 reverse 54321)

here u go...

Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int num,r;
clrscr();
printf("Enter a number");
scanf("%d",&num);
printf("The reversed number is");
cd:
r=num%10;
printf("%d",r);
num=num/10;
if(num>0)
goto cd;
getch();
}

hope this works out...
The Incredible
Sep 15, 2005 at 5:41 PM
ur posts also make me think that u studied it in college.

BTW is it a prog fro c++ or c? i'm not knowin da lang of c but know sumthing abt c++

i don't know whether it is correct or not but accord to my sir it shud b sumthing like this:

Code:
#include<math.h?
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c=0;
cout<<"Enter the five digit number = ";
cin>>a;
b=a%10;
c=c*10+b;
a=a/10;
b=a%10;
c=c*10+b;
a=a/100;
b=a%10;
c=c*10+b;
a=a/1000;
b=a%10;
c=c*10+b;
cout<<"Reversed Digit = "<<c;
getch();
}

Can u solve it out as when i run it, it gives wrong answer. plz tell me my fault.

da progs has to b made like this only as they r in gen section

BTW any suggestions abt da other prog.

Thanks for ur try.

Anindya Srivastava
tuxfan
tuxfan #35
Sep 15, 2005 at 5:47 PM
As far as I remember, for compound interest this is the formula. Confirm this with your school text book.

P (1+(R/100)) ^ N

P is principal
R is Rate of interest
N is number of years

Declare a unsigned double / float variable to store the answer.

Use scanf to get the answers from keyboard
Use this formula and issue a printf for showing the answer. Pretty simple right? Don't expect full code. Logic and tips are right here ;)
The Incredible
Sep 15, 2005 at 5:52 PM
DAMN DAMN DAMN THANKS TUXFAN!!!!!!!

But as i'm not a brainiac plz

let me know wat's a printf n scanf

btw i don't want da full code but da basics n logics also.

but as i'm new to it then it wud b helpful if u gimme answer with which header files 2 use n da basics n logics.

Thanks again and again and again :p :p

Anindya Srivastava
P
Sep 15, 2005 at 5:58 PM
i am giving you this link you can download programs and projects from here
i know it will be ver useful
*nitinkapoor.esmartguy.com/
C
cancer10 #38
Sep 15, 2005 at 6:06 PM
Wow! you guys have a great knowledge in C, C++
The Incredible
Sep 15, 2005 at 6:07 PM
now u ppl r making me say

DDDDDDDDDDDDAAAAAAAAAAAAAAAAAAAMMMMMMMMMMMMMMMNNNNNNNNNNNNN TTTTTTTTTTTHHHHHHHHAAAAAAANNNNNKKKKKKKSSSS!!!!!!!

BTW anything abt da reversal prog mr tuxfan?

Anindya Srivastava
A
Sep 15, 2005 at 6:25 PM
Hey ppl... he wanted it in C++ not in C...
And Incredible your sir has given code for only 5 digit no. What code I;m giving is for n no. of digits
Here is problem 7
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,n,rev=0,z;
cout<<"\nEnter number to be reversed:";
cin>>n;
x=n;
while(n!=0)
{
z=n%10;
n=n/10;
rev=(rev*10)+z;
}
cout<<"\The reverse of "<<x<<" is "<<rev;
getch();
}

Here is the other one:::: That is for Compuond Interest...
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float p,r,n,ci;
cout<<"\nEnter principal:";
cin>>p;
cout<<"\nEnter rate:";
cin>>r;
cout<<"\nEnter time:";
cin>>n;
ci=p*pow((1+(r/100)),n);
cout<<"\nThe compound interest is: "<<ci;
getch();
}
The Incredible
Sep 15, 2005 at 6:37 PM
hey anubhav thanks for da ci one it worked thanks a lot.

BTW can u tell me da prog only for 5 digits with giving info on which headers files 2 use

don't mention getch
}
void main

itna to mujhe bhi aata hain aur type karte samay time bhi bachega
A
Sep 15, 2005 at 6:44 PM
The Incredible said:
hey anubhav thanks for da ci one it worked thanks a lot.

BTW can u tell me da prog only for 5 digits with giving info on which headers files 2 use

don't mention getch
}
void main

itna to mujhe bhi aata hain aur type karte samay time bhi bachega

This is for n digits... so it is valid for five,sx,seven.... Just input hte no. and youll get the reversed no. I have used loops your sir has not... you can see he has used the same two or three lines over and over again... if it was a 15digit no. then what would he have done?????
The Incredible
Sep 15, 2005 at 6:52 PM
yaar anubhav sir ne loop use karne se mana kiyahai.

loop half-yearly ke baad
mohit sharma
Sep 15, 2005 at 6:57 PM
well ' LET US C++ ' by yaswant kanitkar is i think good for u ,
but computer science with c++ by sumita arora can help u 2 ways by teaching u c++ , as well as will help u as course text ( if u are cbse student of 11th and 12th ).
A
Sep 15, 2005 at 6:59 PM
The Incredible said:
yaar anubhav sir ne loop use karne se mana kiyahai.

loop half-yearly ke baad

Then your sir's code is fine since he has told not to use loops...
The Incredible
Sep 15, 2005 at 7:04 PM
i'm cbse 9th

vaise anubhav vo code kam nahi kar raha hai

main 12345 enter karta hun to -11936 jaisa ans aata hai
A
Sep 15, 2005 at 7:36 PM
The Incredible said:
i'm cbse 9th

vaise anubhav vo code kam nahi kar raha hai

main 12345 enter karta hun to -11936 jaisa ans aata hai

Which code??? Mine or ur sirs...
I modified your sirs code.. it had errors....
Code:
#include<math.h>
#include<iostream.h>
#include<conio.h>
void main()
{       clrscr();
	long int x,a,b,c=0;
	cout<<"\nEnter the five digit number = ";
	cin>>a;
	x=a;
	b=a%10;
	c=c*10+b;
	a=x/10;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/100;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/1000;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/10000;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	cout<<"\nReversed Digit = "<<c;
	getch();
}
the lines cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c; is only for seeing what is happening in the program... u can omit them... next long int has to be used since int ranges from -32678 to +32678 so no. greater that 23678 will be displayed as garbage... check it out.. if it doesnt run just reply....
ashu888ashu888
Sep 15, 2005 at 8:17 PM
Hey incredible buddy..jus see this mayb i can help...

Q) WAPC (write a program in C) to ask user for a 5 DIGIT number and print it in reverse order.
-------------------------------------------------------------------------------------------------------------------------

#include<iostream.h>
#include<conio.h>
void main()
{ long int a,b,c,d,e,f,g,h,n;
clrscr();
cout<<"Please enter a 5 DiGIT number:";
cin>>n;
cout<<endl<<endl<<"The 5 DIGIT number entered by you is="<<n;

a=n%10; // This will store the Remainder
b=n/10; // This will store the Quotient
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
h=f/10;

cout<<endl<<endl<<"The 5 DIGIT number in Reverse order is="<<a<<c<<e<<g<<h;

getch();
}

/* OUTPUT:
Please enter a 5 DiGIT number:12345

The 5 DIGIT number entered by you is=12345

The 5 DIGIT number in Reverse order is=54321 */

------------------------------------------------------------------------------------------------------------------------------

Hope this helps u out mate !!:)

Cheers n e-peace...
The Incredible
Sep 15, 2005 at 11:24 PM
anubhav_har said:
Which code??? Mine or ur sirs...
I modified your sirs code.. it had errors....

Of Course of my sir.

BTW i hav yet not modified it as yours.

i'm gonna do rite after i disconnect.

Anindya
Thor
Thor #50
Sep 16, 2005 at 12:31 AM
@ashu888ashu888 :) Actually ur code will just do Fine with ANY 5 digit Number irrespective of the order of occurence of the Digits.

Without Using Loops..ashu888ashu888 's code is just Fine.
Also the CI code from anubhav_har works 4 u...
So Nothing more to add there...
I will only drop in with few helpfull Programming tips:
While u r declaring the Variables..name them in a meaningful way so that when u encounter a variable in ur code u can recall what it does..
Like in 5-digit no. reversal prog. It wud be better if u declare :
long int num,copy,digit1,digit2,digit3,digit4,digit5,quotient.
Where..
num stores the number
copy will store a copy of num It is a good programming practice to unalter the original input. Becoz u may need the original input later in a relatively bigger Program.So a single step copy=num will do it. Then u can do all ur operations on copy keeping num safely unaltered..
digit1 Stores the 1st Digit [or Last of Original Number

digit2 Stores 2nd Digit [or 4th of Original]
digit3...
digit4...
digit5...
quotient stores the quotient after each step.
instead of
b=n/10;
d=b/10;
f=d/10;
.....
to store the quotient if u write
quotient=quotient/10 then after each step only the latest quotient is stored thus reducing ur burden of more variables...
so a better and modeified code [from Point of view of Healthy Programming Practices] wud be:

#include<iostream.h>
#include<conio.h>

void main()
{
long int num,copy,quotient,digit1,digit2,digit3,digit4,digit5;
clrscr();
cout<<"Please enter a 5 DiGIT number:";
cin>>num;
copy=num; // Copy Stores a Duplicate of Num
cout<<endl<<endl<<"The 5 DIGIT number entered by you is="<<copy;

digit1=copy%10;
quotient=copy/10;
digit2=quotient%10;
quotient=quotient/10;
digit3=quotient%10;
quotient=quotient/10;
digit4=f%10;
digit5=quotient/10; //As quotient/10 yields a single digit ->the 1st of Original and Last for Reversed Number

cout<<endl<<endl<<"The 5 DIGIT number in Reverse order is="<<digit1<<digit2<<digit3<<digit4<<digit5;
getch();
}


So that wraps that up except.... the program prints the digits of original number in reverse..does it actuall reverses the Number ??? No.
So here u go...


#include<iostream.h>
#include<conio.h>

void main()
{
long int num,copy,revnum=0,remainder;
cout<<"Enter the 5 digit Number: ";
cin>>num;
copy=num;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
cout<<"\nThe Reversed Number is :"<<revnum;
getch();
}


Which is similar to ur sirs code.. except 4 variable names which r made clearer.
The Incredible
Sep 16, 2005 at 5:20 PM
Hey Anubhav!

Thanks a lot!


Since u don't mind so, I'm some more progs which i've to make b4 my half-yearly exams.

I don't know how to make them so if u gimme da progs alongwith basic concepts, it wud b mor helpful.

Here's 2nd & 3rd part of Question Bank


Use of "if" statement :-

1. To get da gr8er no. among 2 given no.s

2. While purchasing certain items, a discount of 10% if offered if da quantity purchased is more than 1000. If quantity n price per item r entered thru keyboard. WAP to calculate da total expenses.

3. Da current yr n da yr in which da employee joind da organisation r entered thru da keyboard. If da no. of yr for which da employee has served da organisation is gr8er than 3 yrs then a bonus of Rs. 2500/- is given to da employee. If da yr of service isn't gr8er than 3 yrs, then da prog shud not do anything.


Use of "if-else" statement:-

1. whether a no. is even or odd.

2. If his basic salary is less than Rs.1500/-, then HRA - House Rent Aloowance = 10% of BS & DA Dearness Allowance = 90% of BS. If his BS is either equal to or above than Rs.1500/- then HRA = Rs. 500/- & DA = 98% of BS. If da employee's salary is inputed thru keyboard. Write a prog to find his gross salary (Net Salary).

3. Temperature conversion prog that gives da user the option of converting "Fahrenheit to Celsius" or "Celsius to Fahrenheit" & depending upon user's choice carries out da conversation.

4. WAP to calculate & print roots of a quadratic equation ( ax2 + bx + c ).

5. WAP to check da given no. is Palendrome or not. [Note:- What is a Palendrome?]

6. WAP to read 4 values a,b,c & d from da terminal n calculate da ratio of (a+b) to (c-d) & print da result, if (c-d) isn't equal to zero.

I know that da query is very very long, i'm heartily sorry for that but i'm in need so kindly plz help me.

Bye.

Anindya
A
Sep 16, 2005 at 6:47 PM
Here are most of the programs.
Greater of two numbers...
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"\nEnter two numbers:";
cin>>a>>b;
if(a>b)
cout<<a<<" is greater than "<<b;
if(b>a)
cout<<b<<" is greater than "<<a;
getch();
}

Discount program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int quan;
float price,total,disc,finalexp;
cout<<"\nEnter quantity:";
cin>>quan;
cout<<"\nEnter price per item:";
cin>>price;
total=quan*price;
disc=(0.1*total);
if(quan>1000)
{
finalexp=total-disc;
cout<<"\nFinal costs with discount is:"<<finalexp;
}
if(quan<1000)
{
cout<<"\nFinal costs with discount is:"<<finalexp;
}
getch();
}

Bonus program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int yrjoin,curyr,bonus;
cout<<"\nEnter year of joining:";
cin>>yrjoin;
cout<<"\nEnter current year :";
cin>>curyr;
if(curyr<yrjoin)
{
cout<<"\nCUrrent year is less than joining year... Not possible...";
}
if((curyr-yrjoin)>=3)
{
bonus=2500;
cout<<"\nThe employee gets an bonus of:"<<bonus;
}
getch();
}

No is odd or even..
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int no;
cout<<"\nEnter number:";
cin>>no;
if(no%2==0)
{
cout<<"\nNo is even.....";
}
else
{
cout<<"\nNo is odd......";
}
getch();
}

Basic salary program
#include<iostream.h>
#include<conio.h>
void main()
{
// clrscr();
float bs,hra,bsda,net;
cout<<"\nEnter Basic Salary:";
cin>>bs;
if(bs<1500)
{
hra=0.10*bs;
bsda=0.90*bs;
net=bs+hra+bsda;
}
else
{
hra=500;
bsda=0.98*bs;
net=bs+hra+bsda;
}
cout<<"\nThe net salary is:"<<net;
// getch();
}

Temp conv.
#include<iostream.h>
#include<conio.h>
void main()
{
// clrscr();
int opt;
float cel,fah;
cout<<"\nEnter\n1 for cel to fah\n2 for fah to cel\n";
cin>>opt;
if(opt==1)
{
cout<<"\nEnter temp in celcius:";
cin>>cel;
fah=((9*cel)+160)/5;
cout<<"\nThe temp is fahrenheit:"<<fah;
}
else
{
cout<<"\nEnter temp in fahrenhiet:";
cin>>fah;
cel=((5*fah)-160)/9;
cout<<"\nThe temp is celcius:"<<cel;
}

// getch();
}

Palindrome
//Pallindrome... It is like 12321... i.e. reverse of 12321 is 12321 same....
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,n,rev=0,z;
cout<<"\nEnter number to be reversed:";
cin>>n;
x=n;
while(n!=0)
{
z=n%10;
n=n/10;
rev=(rev*10)+z;
}
if(x==rev)
{
cout<<"\nIt is a palindrome..";
}
else
{
cout<<"\nNot a palindorme..";
}
getch();
}
NikhilVerma
Sep 16, 2005 at 7:30 PM
I think it is very bad on your part to request more programs fro digit users...
When you haven't tried making one on your own...
This won't work dude ! Try to make some programs on your own okay ?
BTW I'm only giving the concept of each program... Try to make them on your own..
If you are unsuccesful...
Try again
And then try once more
After that you should post it over here...

If anyone gives you the programs then he is ruining your future !

###############################################

1) Simple, input two numbers, use if to compare two numbers, e.g if(a>b) , if the condition is true print a else print b.
Dude this is the simplest program. What books are you reading ??

2) Again a simple one... Input the quantity and the price... if(quantity>1000) then price = price - price*0.1 , print price

3) Input two years, if( (yearone - yeartwo) >3 ) print bonus else do nothing

###############################################

1) if (no % 2 ==0) Number is even else odd

2) if (salary < 1500) then [salary = salary + salary*10/100 + salary*90/100] else [salary = salary + 500 + salary*98/100 ]

3) input the choice and the option... For eg option 1 is for C-F and 2 is for reverse...
Then if (option==1) variable = 9*temperature/5 + 32 if (option ==2) variable =(f-32)*5/9

4) Enter a,b,c
If (b^2 - 4*a*c is less than 0) then give error coz the roots are imaginary
else
root1=(-b+sqrt(b*b-4*a*c))/(2*a)
root2=(-b-sqrt(b*b-4*a*c))/(2*a)
print the roots...

5) Palindrome is a number which on reversing is the same as the first one.
This could be a tough one for you... So here is the number reversal function

Code:
int reverse(int a)
{
	int b=0,temp;
	while (a!=0)
	{
		temp=a%10;
		a=a/10;
		b=(b*10)+temp;
	}
	return b;
}
void

This will reverse and return the number... Now all you have to do is store it in a variable and check if they are equal or not..

6) input a,b,c,d if ((c-d) >0) then print (a+b)/(c-d) else print error....
A
Sep 16, 2005 at 9:09 PM
Hey Nikhil what you told is correct... but the dude needs it for his exams now.. so why not give it to him.. maybe he is not able to do it... Maybe he can but does not want to... but as he requested it from us we have given him the programs...
The Incredible
Sep 17, 2005 at 12:01 AM
Thanks Anubhav!

A Milliondollar thanks.



BTW Nikhil, ur arguement is absolutely fine.

But let me tel u that v hardly get any theoretical classes.

in our practicals da teacher comes n asks us sum progs 2 make but don't giv us mor info n then he departs after that u hav 2 search him in da whole school 2 get mor info.

v haven't given any buk.

there's a buk in lib but in it there's nothing abt C++

i searched bukstalls but they 2 hav only a question bank.

so that's why i opted it here n as my compu exam is on 30th i need 2 work out which is not possible as i hav 2 luk for other sub also.

Hopt u understud.


BTW any1 knowing da other 2 progs.
Nikhil if u know plz tel me, plz i'm in need.

Anindya
tuxfan
tuxfan #56
Sep 17, 2005 at 12:28 AM
I agree with Nikhil. Why give code? What will this fella learn then? That is why I gave him hints in broadest terms and other over-enthu people gave him code. C'mon guys, you are not helping him by giving him code. :|
M
mach #57
Sep 17, 2005 at 1:07 AM
The Incredible said:
Thanks Anubhav!

A Milliondollar thanks.



BTW Nikhil, ur arguement is absolutely fine.

But let me tel u that v hardly get any theoretical classes.

in our practicals da teacher comes n asks us sum progs 2 make but don't giv us mor info n then he departs after that u hav 2 search him in da whole school 2 get mor info.

v haven't given any buk.

there's a buk in lib but in it there's nothing abt C++

i searched bukstalls but they 2 hav only a question bank.

so that's why i opted it here n as my compu exam is on 30th i need 2 work out which is not possible as i hav 2 luk for other sub also.

Hopt u understud.


BTW any1 knowing da other 2 progs.
Nikhil if u know plz tel me, plz i'm in need.

Anindya

hi there,
i kinda agree with nikhil and tuxfan here..
Guys by handing out the source code.. u r making him dependant..
y giv out the code
u can just explain him the flow or the logic sing an algorithm.. i am sure most of us here are well versed in writing a simple algorithm explaining teh steps to perform

@ incredible

ur exams are on the 30th.. i understand u r a bit worried..
but my friend a simple question..
U r aware of forums.. u know how to search (especially google by what i see among the other posts)
there are parctically 100's of sites on the web which explain u teh concepts of c/c++ more than books (they also giv relevant examples on most needed concepts and many can even be downloaded some r just in kbs-mbs in size).. so stating that u couldnt find a book in collz library.. i find is a huge understatement!!!
sorry if u get offended.. but i just feel that instead of depending on others to solve ur problem completely.. u shuld put some self-effort
A
Sep 17, 2005 at 7:57 AM
heys guys after reading som many comments I completely agree with you....

Hey Incredible sorry won't give you any more codes...
You can downlaod C++ ebook from
Code:
*www.planetpdf.com/codecuts/pdfs/eckel/TIC2Vone.zip
*www.planetpdf.com/codecuts/pdfs/eckel/TIC2Vtwo.zip
As for your other two programs...
for the quadratic... roots of the equations are (-b+sqroot((b*b)-(4*a*c)))/2a and (b+sqroot((b*b)-(4*a*c)))/2a,.... Now you write the code segment,,

for the ratio one if(c-d>0) then evaluate (a+b)/(c-d)
I cant tell you more than that..
ashu888ashu888
Sep 17, 2005 at 1:29 PM
hey Incredible,buddy plz try out these common things urself...

There are also a couple of sites wich can help u as mentioned by so many users..Please make an effort as to how the things will work out...

Wenever a problem is given to u..jus try to imagine..wat would u hv done wen u were in tat situation.How would u hv given the numbers to the Compiler and expected an answer..This thinking strategy will help u solve all ur problems.

If u r facing problems in writing the code in C++ syntax (grammar) then u can also consult a lot of books/online tutorials to help u..

But according to my personal experience..its better to get a book of an Indian writer to make u understand the fundamentals and basics of C++

Coz the same program (of 5 digits) was given by me and many other users also...All mean the same thing brother :) onyl that the way of writing is a bit different varying only in variable names...:)

cheers n e-peace....
The Incredible
Sep 17, 2005 at 1:30 PM
C'mon Guys!

i'm not having time to read da buks n uderstand da logics.

i've already mentioned that my compu exams r on 30th.

man do u all want that i shud only concentrate on comp. man this is cbse board i hav other subjects too. this yr only joined this school.

n abt gaining knowledge let me tel u there's a institute around 2 km from my house for learning programming languages such as BASIC C++ COBOL and JAVA. but currently i'm not having time to read n understand them. from 20th my exams r beginning.

also, in case of reading e-buks electricity needs to b there. if u don't trust just join my city nthemn u'll cum to know da condition of electricity.

my ups remains only upto 5 min.

i don't hav any inverter nor generator.

plz let me solve these progs now.

if i ever ask again after my exams like then i requests da administrator to ban me.


PS: If any 1 having code plz provide me.


Anindya
The Incredible
Sep 17, 2005 at 1:42 PM
mohit sharma said:
well ' LET US C++ ' by yaswant kanitkar

Let me know abt da publisher.

Anindya
ashu888ashu888
Sep 17, 2005 at 1:48 PM
We r here to help u for ur exams buddy..dont worry....we all will help u as ur exams r near and we understand ur situation..so dont panic..:)

cheers n e-peace...
The Incredible
Sep 17, 2005 at 1:56 PM
Thanks ashu888ahsu888 for that kinda reply.

thanks a lot.


Anindya
ashu888ashu888
Sep 17, 2005 at 2:02 PM
Always Incredible..:)

U can hv all ur posts covered in this thread and we wil help u in wat ever way we can....I know the pressures of exam buddy...but did all the previous codes workd on ur compiler>?>

cheers n e-peace...
The Incredible
Sep 17, 2005 at 2:09 PM
Thanks!

No. I've only saved 'em in cpp format. sum of da progs i've ran. n they worked but i'm having confusion with compound interrest prog.

i entered

P = 100

I = 10

T = 2

then i got

CI = 121

but accord 2 me, it shud b 11


BTW if u know abt da rest 2 progs plz let me know.


Anindya
ashu888ashu888
Sep 17, 2005 at 2:19 PM
According to me..in Compound interest,the Amount (Principle+Interest) of the first year becomes the Principle for the second year (im not sure abt the funda thou.. :? ) and so on..so maybe u can use this funda and use it in the program...

That it: Amount=(P*N*R)/100 and this Amount will become the Principle for the 2nd year and so on.....

But its better to understand the concept of all these programs rather than MUGGING all up coz then u will forget everything buddy....so jus make sure that u understand the program...its concepts..and then apply ur codes..:)

cheers n e-peace....
The Incredible
Sep 17, 2005 at 2:27 PM
well i know da pricipal changes every year but man i've asked for ci not p

ci of next year shud b 11


BTW i know that i need to understand basic concepts that's why i've asked plz provide codes with header files n basic concepts n logics.


BTW wat's algorithm. my eng is a bit bad.

PS: if any1 having codes of da rest 2 progs plz gimme.


Anindya
A
Sep 17, 2005 at 3:15 PM
Which codes do you need now.. and the compound intrerest problem I mentioned was working fine.. check again..
A
Sep 17, 2005 at 3:32 PM
Hey man compund interest is amount - principle... amount formula is P[(1+(R/100))^n] therefore there are changes in the code i gave
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float p,r,n,ci,amount;
cout<<"\nEnter principal:";
cin>>p;
cout<<"\nEnter rate:";
cin>>r;
cout<<"\nEnter time:";
cin>>n;
amount=p*pow((1+(r/100)),n);
ci=amount-p;
cout<<"\nThe compound interest is: "<<ci;
getch();
}
Quadratic eqn program
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,d,sqrtd,r1,r2;
cout<<"\nEnter values of a,b,and c for equation ax^2+bx+c:";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
sqrtd=sqrt(d);
r1=(-b+sqrtd)/(2*a);
r2=(-b-sqrtd)/(2*a);
cout<<"\nThe roots are: "<<r1<<","<<r2;
getch();
}
The Incredible
Sep 17, 2005 at 3:41 PM
Hey!

Thanks a lotta!

in ur formula u wrote ^N

but in coed u rote ,N

also wat does pow stands for?



PS: if any1 last program , plz let me know.

Anindya
M
mach #71
Sep 17, 2005 at 5:07 PM
Hey Incredible.. as it seems u have some time to spend around on this forum..

here 's a c++ primer for you.. this can get u thru some of the basic stuff that u ought to know be4 giving a c++ written/practical/oral exam
Hope this helps you to some extent
The content on c++ i am providing is from this site

Code:
*www.cprogramming.com/tutorial.html

Code:
 Lesson 1

C++ is a programming language of many different dialects, similar to the way that each spoken language has many different dialects. In C++, dialects are not because the speakers live in the North or South. Instead, it is because there are many different compilers that support slightly different features. There are several common compilers: in particular, Borland C++, Microsoft C++, and GNU C++. There are also many front-end environments for the different compilers--the most common is Dev-C++ around GNU's G++ compiler. Some, such as G++, are free, while others are not. Please see the compiler listing for more information on how to get a compiler and set it up.

Each of these compilers is slightly different. Each one should support the ANSI/ISO standard C++ functions, but each compiler will also have nonstandard functions (these functions are similar to slang spoken in different parts of a country). Sometimes the use of nonstandard functions will cause problems when you attempt to compile source code (the actual C++ written by a programmer and saved as a text file) with a different compiler. These tutorials use ANSI/ISO standard C++ and should not suffer from this problem (with sufficiently modern compilers). Note that if you are using an older compiler, such as TCLite, you should read check out some compatability issues.

If you don't have a compiler, I strongly suggest that you get one. A simple compiler is sufficient for our use, but make sure that you do get one in order to get the most from these tutorials. The page linked above, compilers, lists compilers by operating system.

C++ is a different breed of programming language. A C++ program begins with a function, a collection of commands that do "something". The function that begins a C++ program is called main; this function is always called when the program first executes. From main, we can also call other functions whether they be written by us or by others. To access a standard function that comes with the compiler, you include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. Let's look at a working program:

Code:
#include <iostream>

using namespace std;

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();
}

Let's look at the elements of the program. The #include is a "preprocessor" directive that tells the compiler to put code from the header called iostream into our program before actually creating the executable. By including header files, you an gain access to many different functions. For example, the cout function requires iostream. Following the include is the statement, "using namespace std;". This line tells the compiler to use a group of functions that are part of the standard library (std). By including this line at the top of a file, you allow the program to use functions such as cout. The semicolon is part of the syntax of C and C++. It tells the compiler that you're at the end of a command. You will see later that the semicolon is used to end most commands in C++.

The next imporant line is int main(). This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. The "curly braces" ({ and }) signal the beginning and end of functions and other code blocks. If you have programmed in Pascal, you will know them as BEGIN and END. Even if you haven't programmed in Pascal, this is a good way to think about their meaning.

The next line of the program may seem strange. If you have programmed in another language, you might expect that print would be the function used to display text. In C++, however, the cout object is used to display text. It uses the << symbols, known as "insertion operators", to indicate what to output. cout<< results in a function call with the ensuing text as an argument to the function. The quotes tell the compiler that you want to output the literal string as-is. The '\n' sequence is actually treated as a single character that stands for a newline (we'll talk about this later in more detail). It moves the cursor on your screen to the next line. Again, notice the semicolon: it is added onto the end of all, such as function calls, in C++.

The next command is cin.get(). This is another function call: it reads in input and expects the user to hit the return key. Many compiler environments will open a new console window, run the program, and then close the window. This command keeps that window from closing because the program is not done yet because it waits for you to hit enter. Including that line gives you time to see the program run.

Upon reaching the end of main, the closing brace, our program will return the value of 0 (and integer, hence why we told main to return an int) to the operating system. This return value is important as it can be used to tell the OS whether our program succeeded or not. A return value of 0 means success and is returned automatically (but only for main, other functions require you to manually return a value), but if we wanted to return something else, such as 1, we would have to do it with a return statement:

Code:
#include <iostream>

using namespace std;

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();

  return 1;
}
The final brace closes off the function. You should try compiling this program and running it. You can cut and paste the code into a file, save it as a .cpp (or whatever extension your compiler requires) file. If you are using a command-line compiler, such as Borland C++ 5.5, you should read the compiler instructions for information on how to compile. Otherwise compiling and running should be as simple as clicking a button with your mouse.

You might start playing around with the cout function and get used to writing C++.

Comments are critical for all but the most trivial programs and this tutorial will often use them to explain sections of code. When you tell the compiler a section of text is a comment, it will ignore it when running the code, allowing you to use any text you want to describe the real code. To create a comment use either //, which tells the compiler that the rest of the line is a comment, or /* and then */ to block off everything between as a comment. Certain compiler environments will change the color of a commented area, but some will not. Be certain not to accidentally comment out code (that is, to tell the compiler part of your code is a comment) you need for the program. When you are learning to program, it is useful to be able to comment out sections of code in order to see how the output is affected.

So far you should be able to write a simple program to display information typed in by you, the programmer and to describe your program with comments. That's great, but what about interacting with your user? Fortunately, it is also possible for your program to accept input. The function you use is known as cin, and is followed by the insertion operator >>.

Of course, before you try to receive input, you must have a place to store that input. In programming, input and data are stored in variables. There are several different types of variables; when you tell the compiler you are declaring a variable, you must include the data type along with the name of the variable. Several basic types include char, int, and float.

A variable of type char stores a single character, variables of type int store integers (numbers without decimal places), and variables of type float store numbers with decimal places. Each of these variable types - char, int, and float - is each a keyword that you use when you declare a variable.

Sometimes it can be confusing to have multiple variable types when it seems like some variable types are redundant. Using the right variable size can be important for making your code readable and for efficiency--some variables require more memory than others. For now, suffice it to say that the different variable types will almost all be used!

To declare a variable you use the syntax type <name>. It is permissible to declare multiple variables of the same type on the same line; each one should be separated by a comma. The declaration of a variable or set of variables should be followed by a semicolon (Note that this is the same procedure used when you call a function). If you attempt to use an undefined variable, your program will not run, and you will receive an error message informing you that you have made a mistake.

Code:
Here are some variable declaration examples: 
 
int x;
int a, b, c, d;
char letter;
float the_float;

While you can have multiple variables of the same type, you cannot have multiple variables with the same name. Moreover, you cannot have variables and functions with the same name.

Code:
Here is a sample program demonstrating the use a a variable: 
 
#include <iostream>

using namespace std;

int main()
{
  int thisisanumber;

  cout<<"Please enter a number: ";
  cin>> thisisanumber;
  cin.ignore();
  cout<<"You entered: "<< thisisanumber <<"\n";
  cin.get();
}

Let's break apart this program and examine it line by line. The keyword int declares thisisanumber to be an integer. The function cin>> reads a value into thisisanumber; the user must press enter before the number is read by the program. cin.ignore() is another function that reads and discards a character. Remember that when you type intput into a program, it takes the enter key too. We don't need this, so we throw it away. Keep in mind that the variable was declared an integer; if the user attempts to type in a decimal number, it will be truncated (that is, the decimal component of the number will be ignored). Try typing in a sequence of characters or a decimal number when you run the example program; the response will vary from input to input, but in no case is it particularly pretty. Notice that when printing out a variable quotation marks are not used. Were there quotation marks, the output would be "You Entered: thisisanumber." The lack of quotation marks informs the compiler that there is a variable, and therefore that the program should check the value of the variable in order to replace the variable name with the variable when executing the output function. Do not be confused by the inclusion of two separate insertion operators on one line. Including multiple insertion operators on one line is perfectly acceptable and all of the output will go to the same place. In fact, you must separate string literals (strings enclosed in quotation marks) and variables by giving each its own insertion operators (<<). Trying to put two variables together with only one << will give you an error message, do not try it. Do not forget to end functions and declarations with a semicolon. If you forget the semicolon, the compiler will give you an error message when you attempt to compile the program.

Of course, no matter what type you use, variables are uninteresting without the ability to modify them. Several operators used with variables include the following: *, -, +, /, =, ==, >, <. The * multiplies, the - subtracts, and the + adds. It is of course important to realize that to modify the value of a variable inside the program it is rather important to use the equal sign. In some languages, the equal sign compares the value of the left and right values, but in C++ == is used for that task. The equal sign is still extremely useful. It sets the left input to the equal sign, which must be one, and only one, variable equal to the value on the right side of the equal sign. The operators that perform mathematical functions should be used on the right side of an equal sign in order to assign the result to a variable on the left side.

Code:
Here are a few examples: 
 
a = 4 * 6; // (Note use of comments and of semicolon) a is 24
a = a + 5; // a equals the original value of a with five added to it
a == 5     // Does NOT assign five to a. Rather, it checks to see if a equals 5
.

The other form of equal, ==, is not a way to assign a value to a variable. Rather, it checks to see if the variables are equal. It is useful in other areas of C++; for example, you will often use == in such constructions as conditional statements and loops. You can probably guess how < and > function. They are greater than and less than operators.

Code:
For example: 
 
a < 5  // Checks to see if a is less than five
a > 5  // Checks to see if a is greater than five
a == 5 // Checks to see if a equals five, for good measure
M
mach #72
Sep 17, 2005 at 5:11 PM
Code:
Lesson 2: If statements

The ability to control the flow of your program, letting it make decisions on what code to execute, is valuable to the programmer. The if statement allows you to control if a program enters a section of code or not based on whether a given condition is true or false. One of the important functions of the if statement is that it allows the program to select an action based upon the user's input. For example, by using an if statement to check a user entered password, your program can decide whether a user is allowed access to the program.

Without a conditional statement such as the if statement, programs would run almost the exact same way every time. If statements allow the flow of the program to be changed, and so they allow algorithms and more interesting code.

Before discussing the actual structure of the if statement, let us examine the meaning of TRUE and FALSE in computer terminology. A true statement is one that evaluates to a nonzero number. A false statement evaluates to zero. When you perform comparison with the relational operators, the operator will return 1 if the comparison is true, or 0 if the comparison is false. For example, the check 0 == 2 evaluates to 0. The check 2 == 2 evaluates to a 1. If this confuses you, try to use a cout statement to output the result of those various comparisons (for example cout<< ( 2 == 1 );)

When programming, the aim of the program will often require the checking of one value stored by a variable against another value to determine whether one is larger, smaller, or equal to the other.

There are a number of operators that allow these checks.

Code:
Here are the relational operators, as they are known, along with examples: 
 
>     greater than              5 > 4 is TRUE
<     less than                 4 < 5 is TRUE
>=    greater than or equal     4 >= 4 is TRUE
<=    less than or equal        3 <= 4 is TRUE
==    equal to                  5 == 5 is TRUE
!=    not equal to              5 != 4 is TRUE

It is highly probable that you have seen these before, probably with slightly different symbols. They should not present any hindrance to understanding. Now that you understand TRUE and FALSE in computer terminology as well as the comparison operators, let us look at the actual structure of if statements.

Code:
The structure of an if statement is as follows: 
 
if ( TRUE )
  Execute the next statement

To have more than one statement execute after an if statement that evaluates to true, use braces, like we did with the body of a function. Anything inside braces is called a compound statement, or a block.

Code:
For example: 
 
if ( TRUE ) {
  Execute all statements inside the braces
}
There is also the else statement. The code after it (whether a single line or code between brackets) is executed if the if statement is FALSE.

It can look like this:
Code:
if ( TRUE ) {
  // Execute these statements if TRUE
}
else {
  // Execute these statements if FALSE
}

One use for else is if there are two conditional statements that may both evaluate to true, yet you wish only one of the two to have the code block following it to be executed. You can use an else if after the if statement; that way, if the first statement is true, the else if will be ignored, but if the if statement is false, it will then check the condition for the else if statement. If the if statement was true the else statement will not be checked. It is possible to use numerous else if statements.

Let's look at a simple program for you to try out on your own.

Code:
#include <iostream>	

using namespace std;
		
int main()                            // Most important part of the program!
{
  int age;                            // Need a variable...
  
  cout<<"Please input your age: ";    // Asks for age
  cin>> age;                          // The input is put in age
  cin.ignore();                       // Throw away enter
  if ( age < 100 ) {                  // If the age is less than 100
     cout<<"You are pretty young!\n"; // Just to show you it works...
  }
  else if ( age == 100 ) {            // I use else just to show an example 
     cout<<"You are old\n";           // Just to show you it works...
  }
  else {
    cout<<"You are really old\n";     // Executed if no other statement is
  }
  cin.get();
}

Boolean operators allow you to create more complex conditional statements. For example, if you wish to check if a variable is both greater than five and less than ten, you could use the boolean AND to ensure both var > 5 and var < 10 are true. In the following discussion of boolean operators, I will capitalize the boolean operators in order to distinguish them from normal english. The actual C++ operators of equivalent function will be described further into the tutorial - the C++ symbols are not: OR, AND, NOT, although they are of equivalent function.

When using if statements, you will often wish to check multiple different conditions. You must understand the Boolean operators OR, NOT, and AND. The boolean operators function in a similar way to the comparison operators: each returns 0 if evaluates to FALSE or 1 if it evaluates to TRUE.

NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE. For example, NOT (1) evalutes to 0, and NOT (0) evalutes to 1. NOT (any number but zero) evaluates to 0. In C and C++ NOT is written as !. NOT is evaluated prior to both AND and OR.

AND:
This is another important command. AND returns TRUE if both inputs are TRUE (if 'this' AND 'that' are true). (1) AND (0) would evaluate to zero because one of the inputs is false (both must be TRUE for it to evaluate to TRUE). (1) AND (1) evaluates to 1. (any number but 0) AND (0) evaluates to 0. The AND operator is written && in C++. Do not be confused by thinking it checks equality between numbers: it does not. Keep in mind that the AND operator is evaluated before the OR operator.

OR: Very useful is the OR statement! If either (or both) of the two values it checks are TRUE then it returns TRUE. For example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || in C++. Those are the pipe characters. On your keyboard, they may look like a stretched colon. On my computer the pipe shares its key with \. Keep in mind that OR will be evaluated after AND.

It is possible to combine several boolean operators in a single statement; often you will find doing so to be of great value when creating complex expressions for if statements. What is !(1 && 0)? Of course, it would be TRUE. It is true is because 1 && 0 evaluates to 0 and !0 evaluates to TRUE (ie, 1).

Try these statements for urself


Code:
A. !( 1 || 0 )         ANSWER: 0	
B. !( 1 || 1 && 0 )    ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 )  ANSWER: 1 (Parenthesis are useful)
M
mach #73
Sep 17, 2005 at 5:15 PM
Code:
Lesson 3: Loops

Loops are used to repeat a block of code. Being able to have your program repeatedly execute a block of code is one of the most basic but useful tasks in programming -- many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times. (They may be executing a small number of tasks, but in principle, to produce a list of messages only requires repeating the operation of reading in some data and displaying it.) Now, think about what this means: a loop lets you write a very simple statement to produce a significantly greater result simply by repetition.

One Caveat: before going further, you should understand the concept of C++'s true and false, because it will be necessary when working with loops (the conditions are the same as with if statements). There are three types of loops: for, while, and do..while. Each of them has their specific uses. They are all outlined below.

FOR - for loops are the most useful type. The syntax for a for loop is



Code:
for ( variable initialization; condition; variable update ) {
  Code to execute while the condition is true
}

The variable initialization allows you to either declare a variable and give it a value or give a value to an already existing variable. Second, the condition tells the program that while the conditional expression is true the loop should continue to repeat itself. The variable update section is the easiest way for a for loop to handle changing of the variable. It is possible to do things like x++, x = x + 10, or even x = random ( 5 ), and if you really wanted to, you could call other functions that do nothing to the variable but still have a useful effect on the code. Notice that a semicolon separates each of these sections, that is important. Also note that every single one of the sections may be empty, though the semicolons still have to be there. If the condition is empty, it is evaluated as true and the loop will repeat until something else stops it.

Code:
Example: 
 
#include <iostream>

using namespace std; // So the program can see cout and endl

int main()
{
  // The loop goes while x < 10, and x increases by one every loop
  for ( int x = 0; x < 10; x++ ) {
    // Keep in mind that the loop condition checks 
    //  the conditional statement before it loops again.
    //  consequently, when x equals 10 the loop breaks.
    // x is updated before the condition is checked.    
    cout<< x <<endl;
  }
  cin.get();
}

This program is a very simple example of a for loop. x is set to zero, while x is less than 10 it calls cout<< x <<endl; and it adds 1 to x until the condition is met. Keep in mind also that the variable is incremented after the code in the loop is run for the first time.

WHILE - WHILE loops are very simple. The basic structure is

Code:
while ( condition ) { Code to execute while the condition is true }

The true represents a boolean expression which could be x == 1 or while ( x != 7 ) (x does not equal 7). It can be any combination of boolean statements that are legal. Even, (while x ==5 || v == 7) which says execute the code while x equals five or while v equals 7. Notice that a while loop is the same as a for loop without the initialization and update sections. However, an empty condition is not legal for a while loop as it is with a for loop.

Code:
Example: 
 
#include <iostream>

using namespace std; // So we can see cout and endl

int main()
{ 
  int x = 0;  // Don't forget to declare variables
  
  while ( x < 10 ) { // While x is less than 10 
    cout<< x <<endl;
    x++;             // Update x so the condition can be met eventually
  }
  cin.get();
}

This was another simple example, but it is longer than the above FOR loop. The easiest way to think of the loop is that when it reaches the brace at the end it jumps back up to the beginning of the loop, which checks the condition again and decides whether to repeat the block another time, or stop and move to the next statement after the block.

DO..WHILE - DO..WHILE loops are useful for things that want to loop at least once. The structure is

Code:
do {
} while ( condition );

Notice that the condition is tested at the end of the block instead of the beginning, so the block will be executed at least once. If the condition is true, we jump back to the beginning of the block and execute it again. A do..while loop is basically a reversed while loop. A while loop says "Loop while the condition is true, and execute this block of code", a do..while loop says "Execute this block of code, and loop while the condition is true".
Code:
Example: 
 
#include <iostream>

using namespace std;

int main()
{
  int x;

  x = 0;
  do {
    // "Hello, world!" is printed at least one time
    //  even though the condition is false
    cout<<"Hello, world!\n";
  } while ( x != 0 );
  cin.get();
}
Keep in mind that you must include a trailing semi-colon after the while in the above example. A common error is to forget that a do..while loop must be terminated with a semicolon (the other loops should not be terminated with a semicolon, adding to the confusion). Notice that this loop will execute once, because it automatically executes before checking the condition.
ashu888ashu888
Sep 17, 2005 at 5:15 PM
Hey Mach bro ! Mr.Incredible already said tat he didnt get any help from the site that u mentioned..
M
mach #75
Sep 17, 2005 at 5:18 PM
Code:
Lesson 4: Functions

Now that you should have learned about variables, loops, and conditional statements it is time to learn about functions. You should have an idea of their uses as we have already used them and defined one in the guise of main. cin.get() is an example of a function. In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.

Functions that a programmer writes will generally require a prototype. Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four.

Code:
For example: 
 
#include <cstdlib>   // Include rand()

using namespace std; // Make rand() visible

int a = rand(); // rand is a standard function that all compilers have

Do not think that 'a' will change at random, it will be set to the value returned when the function is called, but it will not change again.

Code:
The general format for a prototype is simple: 
 
return-type function_name ( arg_type arg1, ..., arg_type argN );

arg_type just means the type for each argument -- for instance, an int, a float, or a char. It's exactly the same thing as what you would put if you were declaring a variable.

There can be more than one argument passed to a function or none at all (where the parentheses are empty), and it does not have to return a value. Functions that do not return values have a return type of void. Lets look at a function prototype:

Code:
int mult ( int x, int y );

This prototype specifies that the function mult will accept two arguments, both integers, and that it will return an integer. Do not forget the trailing semi-colon. Without it, the compiler will probably think that you are trying to write the actual definition of the function.

When the programmer actually defines the function, it will begin with the prototype, minus the semi-colon. Then there should always be a block with the code that the function is to execute, just as you would write it for the main function. Any of the arguments passed to the function can be used as if they were declared in the block. Finally, end it all with a cherry and a closing brace. Okay, maybe not a cherry.

Code:
Lets look at an example program: 
 
#include <iostream>

using namespace std;

int mult ( int x, int y );

int main()
{
  int x;
  int y;
  
  cout<<"Please input two numbers to be multiplied: ";
  cin>> x >> y;
  cin.ignore();
  cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
  cin.get();
}

int mult ( int x, int y )
{
  return x * y;
}
This program begins with the only necessary include file and a directive to make the std namespace visible. Everything in the standard headers is inside of the std namespace and not visible to our programs unless we make them so. Next is the prototype of the function. Notice that it has the final semi-colon! The main function returns an integer, which you should always have to conform to the standard. You should not have trouble understanding the input and output functions. It is fine to use cin to input to variables as the program does. But when typing in the numbers, be sure to separate them by a space so that cin can tell them apart and put them in the right variables.

Notice how cout actually outputs what appears to be the mult function. What is really happening is cout is printing the value returned by mult, not mult itself. The result would be the same as if we had use this print instead

Code:
cout<<"The product of your two numbers is "<< x * y <<"\n";

The mult function is actually defined below main. Due to its prototype being above main, the compiler still recognizes it as being defined, and so the compiler will not give an error about mult being undefined. As long as the prototype is present, a function can be used even if there is no definition. However, the code cannot be run without a definition even though it will compile. The prototype and definition can be combined into one also. If mult were defined before it is used, we could do away with the prototype because the definition can act as a prototype as well.

Return is the keyword used to force the function to return a value. Note that it is possible to have a function that returns no value. If a function returns void, the retun statement is valid, but only if it does not have an expression. In otherwords, for a function that returns void, the statement "return;" is legal, but redundant.

The most important functional (Pun semi-intended) question is why do we need a function? Functions have many uses. For example, a programmer may have a block of code that he has repeated forty times throughout the program. A function to execute that code would save a great deal of space, and it would also make the program more readable. Also, having only one copy of the code makes it easier to make changes. Would you rather make forty little changes scattered all throughout a potentially large program, or one change to the function body? So would I.

Another reason for functions is to break down a complex program into logical parts. For example, take a menu program that runs complex code when a menu choice is selected. The program would probably best be served by making functions for each of the actual menu choices, and then breaking down the complex tasks into smaller, more manageable tasks, which could be in their own functions. In this way, a program can be designed that makes sense when read. And has a structure that is easier to understand quickly. The worst programs usually only have the required function, main, and fill it with pages of jumbled code.
M
mach #76
Sep 17, 2005 at 5:20 PM
Code:
Lesson 5: switch case

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The basic format for using switch case is outlined below. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point.


Code:
switch ( <variable> ) {
case this-value:
  Code to execute if <variable> == this-value
  break;
case that-value:
  Code to execute if <variable> == that-value
  break;
...
default:
  Code to execute if <variable> does not equal the value following any of the cases
  break;
}


The condition of a switch statement is a value. The case says that if it has the value of whatever is after that case then do whatever follows the colon. The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. An important thing to note about the switch statement is that the case values may only be constant integral expressions. Sadly, it isn't legal to use case like this:

Code:
int a = 10;
int b = 10;
int c = 20;

switch ( a ) {
case b:
  // Code
  break;
case c:
  // Code
  break;
default:
  // Code
  break;
}

The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch statements serves as a simple way to write long if statements when the requirements are met. Often it can be used to process input from a user.

Below is a sample program, in which not all of the proper functions are actually declared, but which shows how one would use switch in a program.

Code:
#include <iostream>

using namespace std;

void playgame();
void loadgame();
void playmultiplayer();
	
int main()
{
  int input;
  
  cout<<"1. Play game\n";
  cout<<"2. Load game\n";
  cout<<"3. Play multiplayer\n";
  cout<<"4. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  switch ( input ) {
  case 1:            // Note the colon, not a semicolon
    playgame();
    break;
  case 2:            // Note the colon, not a semicolon
    loadgame();
    break;
  case 3:            // Note the colon, not a semicolon
    playmultiplayer();
    break;
  case 4:            // Note the colon, not a semicolon
    cout<<"Thank you for playing!\n";
    break;
  default:            // Note the colon, not a semicolon
    cout<<"Error, bad input, quitting\n";
    break;
  }
  cin.get();
}

This program will compile, but cannot be run until the undefined functions are given bodies, but it serves as a model (albeit simple) for processing input. If you do not understand this then try mentally putting in if statements for the case statements. Default simply skips out of the switch case construction and allows the program to terminate naturally. If you do not like that, then you can make a loop around the whole thing to have it wait for valid input. You could easily make a few small functions if you wish to test the code.
M
mach #77
Sep 17, 2005 at 5:38 PM
ashu888ashu888 said:
Hey Mach bro ! Mr.Incredible already said tat he didnt get any help from the site that u mentioned..

Hi ashu bro..
i havnt yet mentioned a site be4 i posted the tutz.. and i also dont see where mr incredible say he didnt find it useful

he only mentioned that he had no time to search/read books ..
but as i see he is a regualr to the forum even during his exams are so close.. i thnk he and some others mght find this simple tutorial interesting

for a comp exam if it is written.. u ned to know the basic concepts..
even for a practical exam.. basic concepts are somethng that need to be known..same is required if any viva/questions are asked regarding his program
like y he used a loop, why he used if..else control statement and y not while.. switch.. these are basic concepts

its true his exams are near.. but he isnt going to score nythng unless he knows some of the basic stuff.. who knows if he will be asked the same questions he has listed here.. he needs to understand the concepts to some extent

he says he has no time for comp studies.. yet its still on 30.. he has some time.. it wont take more than 30 minutes to read what i have posted and abt 1-2 hrs more to try the codes posted..

if he can spend time on an online forum be4 exams.. i am sure he wont mind spending some time reading the simple tutorial posted especially for him on the forum

these are the simplest tutz i could find when i had started with c++ and so am sharing them.. hope this helps u mr incredible.. and soem others as well...

@ Mr Incredible.. if u have other concepts like function, arrays, structures.. u can spend some time on the site i mentioned atleast ur concepts will be clear to some extent

when i posted the tutz i had in mind that someone else besides mr incredible will also find them useful..

I mean no offense to nyone ..
A
Sep 17, 2005 at 5:51 PM
The Incredible said:
C'mon Guys!

i'm not having time to read da buks n uderstand da logics.

i've already mentioned that my compu exams r on 30th.

man do u all want that i shud only concentrate on comp. man this is cbse board i hav other subjects too. this yr only joined this school.

n abt gaining knowledge let me tel u there's a institute around 2 km from my house for learning programming languages such as BASIC C++ COBOL and JAVA. but currently i'm not having time to read n understand them. from 20th my exams r beginning.

also, in case of reading e-buks electricity needs to b there. if u don't trust just join my city nthemn u'll cum to know da condition of electricity.

my ups remains only upto 5 min.

i don't hav any inverter nor generator.

plz let me solve these progs now.

if i ever ask again after my exams like then i requests da administrator to ban me.


PS: If any 1 having code plz provide me.


Anindya

hey incredible... pow stands for power function.. i.e. if we need to do 2 to the power 3 then we write pow(2,3) The POW function must have a prototype and it is included in the math.h header file.
Second thing if you don't have enough time to read ebooks and learn c++.. then how do you manage to hang around the digit forum for so much time... this is just an excuse for not studying c++.. if we are helping you that does not mean that you don't have to study c++.... if you are a computer freak and wanna study comp sc. or IT in the future then c or c++ is a must for everyone....
ashu888ashu888
Sep 17, 2005 at 6:47 PM
mach wrote:
Hi ashu bro..
i havnt yet mentioned a site be4 i posted the tutz.. and i also dont see where mr incredible say he didnt find it useful
Mr.Incredible said this mach bro :)The-Incredible wrote:
BTW i've tried cprogramming.com provided by digit in three incredibly useful sites sectiond but didn't found anything helpful.
Look at the starting page of this thread buddy..neways i completely agree that we all r saying our point..:) And i aslo agree with u buddy that even ur saying ur point..there is nothing to feel bad about it..:) and im also not blaming any one..:)

Neways its all upto Mr.Incredible to learn or not to learn... :wink:

Cheers n e-peace...
A
Sep 17, 2005 at 7:07 PM
Hey ppl.. why has this post by Mr. Incredible been a post of such discussions... let Mr. Incredible do whatever he wants to... if he is giving us a question just answer it and leave him alone. If he does not want to learn or is not interested in C++ program leave him alone..
A
Sep 17, 2005 at 10:03 PM
Go to www.funducode.com
www.1cpluplusstreet.com
www.programmersheaven.com

Let us C ---- Yashvant Kanetkar
greatttttt book but for C........You can buy it as well ...it will not matter...........for any personal help ...contact me at kallol3408@dataone.in

I am one of the best C++ guy around in Don Bosco,Liluah
If you need help for projects you can contact me tooooo....

My projects are original ....... and mind blowing at the school level......
The Incredible
Sep 18, 2005 at 12:53 AM
thanks abhra_life

n thanks u all fro answering.


esp. mach


A BILLION DOLLAR THANKZ

That's what i exactly wanted.
i copied whole tutorial.

u were correct only half n hour n problem solved.

but on 20th my maths exams.
22 social sc
24 science
26 english
27hindi
29 comp theory
30 comp prac.

now i'll read da tutz ASAP but in case of practice i'll do it on 27 after hindi paper.

Hey anubhav_har

don't b angry with me.

u don't know me.

i buy digit just coz i luv computer tech

also this forum n u ppl may not b available thru out my life.

may b i don't get time for my comp craze.

may b life

who knows?

i can't explain how much big fan of computing.

actually i'm giving time 2 this forum coz i'm knowing i'll b helped here
instead of searching da net. try 2 understand me.

i'm devoting time 2 forum just bcoz my comp exams.
either u believe or not i'm gonna take comp sc in 1sst yr. even if i've to leave cbse board.

plz answer me.

Thanks every1 for that kinda help.

Thanks mach. thanks a lot. i'm not getting words fro how 2 thanks u.


Anindya
The Incredible
Sep 18, 2005 at 12:54 AM
Here's da second last part of my QB

Use of else-if statement
1. WAP to check da y of a wik whether it's Mon, Tue, Wed.....or Sun.

2. WAP to check da month of a yr whether it's Jan.......Dec.

3. Wap to print da grade of a student in an academic session as per as

following rules :-

Avg marks Grade
80 to 100 Honours
60 to 79 1st Div
50 to 59 2nd Div
40 to 49 3rd Div
00 to 39 Fail

4. Wap to find da largest amung 3 no.s.

5. An electric power distribution company charge its domestic consumers

as follows :-

Consumption Unit Rate of Charge
000 to 200 Rs 0.5 /unit
201 to 400 Rs 100 + Rs 0.65 /unit excess of 200 unit
401 to 600 Rs 230 + Rs 0.8/unit excess of 400 unit
600 & above Rs 390 + Rs 1/unit excess of 600 unit

Da prog read da customers no. & power consumed & print da amt 2 b paid

by da customer.

6. WAP to create da equivalent of a 4-function calculator. Da prog

requires da user to enter 2 no. & an operator. It then carries out da

specified arithemetical operation : addition, subtraction,

multiplication or division of da 2 no.


Plz help gimme da code.

Hop u ppl 'll help

Anindya
A
Sep 18, 2005 at 8:26 AM
4.WAp to find the largest no of 3

void main()
{
int a,b,c;
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<a;
}
else
{
if(b>c)
cout<<b;
else
cout<<c;
}
}
A
Sep 18, 2005 at 9:11 AM
1)Day of the week
#include<iostream.h>
#include<conio.h>
void main()
{
int day;
cout<<"\nEnter wihcih day of the week (1-7):";
cin>>day;
if(day<1 || day>7)
cout<<"\nWrong day entered,.,,";
else if(day==1)
cout<<"\nMonday";
else if(day==2)
cout<<"\nTuesday";
else if(day==3)
cout<<"\nWednesday";
else if(day==4)
cout<<"\nThursday";
else if(day==5)
cout<<"\nFriday";
else if(day==6)
cout<<"\nSaturday";
else if(day==7)
cout<<"\nSunday";
}
2) For month of the year
just change day<1 and day>12 in the above program
if 1 then january...
12 then december...

3)Grade of student...
#include<iostream.h>
#include<conio.h>
void main()
{
float avg;
cout<<"\nEnter avg marks(0-100%):";
cin>>avg;
if(avg<0 || avg>100)
cout<<"\nCannot be less than 0 or more than 100,.,,";
else if(avg>=0 && avg<=39)
cout<<"\nFailed....";
else if(avg>=40 && avg<=49)
cout<<"\nThird division";
else if(avg>=50 && avg<=59)
cout<<"\nSecond division";
else if(avg>=60 && avg<=79)
cout<<"\nFirst division";
else if(avg>=80 && avg<=100)
cout<<"\nHonours";
}
4)Already done by abhra_life
5)Electric bill
#include<iostream.h>
#include<conio.h>
void main()
{
int custno;
float avg;
double total;
cout<<"\nEnter customer no:";
cin>>custno;
cout<<"\nEnter no of units:";
cin>>avg;
if(avg>=0 && avg<=200)
total=avg*0.50;
else if(avg>=201 && avg<=400)
total=100+((avg-200)*0.65);
else if(avg>=401 && avg<=600)
total=230+((avg-400)*0.80);
else if(avg>=601)
total=390+((avg-600)*1.00);
cout<<"\nTotal bill for customer no "<<custno<<" for "<<avg<<" units is "<<total;
cout<<endl;
}
6)4 function calculator...
#include<iostream.h>
#include<conio.h>
void main()
{
int opt;
double n1,n2,x;
cout<<"\nEnter:\n1. for addition\n2. for subtraction\n3. for multiplication\n4. for division\n";
cin>>opt;
if(opt<1 || opt>4)
{
cout<<"\nWrong option...";
}
else
{
cout<<"\nEnter number 1:";
cin>>n1;
cout<<"\nEnter number 2:";
cin>>n2;
if(opt==1)
{
x=n1+n2;
cout<<"\nThe sum of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==2)
{
x=n1-n2;
cout<<"\nThe difference of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==3)
{
x=n1*n2;
cout<<"\nThe product of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==4)
{
x=n1/n2;
cout<<"\nThe quotient of "<<n1<<" and "<<n2<<" is "<<x;
}
}
}
A
Sep 18, 2005 at 11:10 AM
A better way of doing 1 & 2 :-

void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day)
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}
ashu888ashu888
Sep 18, 2005 at 11:19 AM
Hey Abhra ,buddy in ur program , the d shud be replaced by the variable name "day" as ur using this variable in the Switch case...:)
void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day) //change it to day buddy..
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}
A
Sep 18, 2005 at 1:56 PM
ashu888ashu888 said:
Hey Abhra ,buddy in ur program , the d shud be replaced by the variable name "day" as ur using this variable in the Switch case...:)
void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day) //change it to day buddy..
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}


sorry fo rth error
change the switch(day) to switch(d)
The Incredible
Sep 18, 2005 at 4:40 PM
Hey!

Guys thanks for very very much helpful reply.

BTW dear abhra_life

i mentioned that da programs r 2 be made with da use of else - if statement.

abt switch. its da last part of my QB


Here it is.

Use of switch statement


1. WAP to check day of a week depending upon user's choice such as (1- Mon, 2- Tue, 3- Wed ........ , 7-Sun & other no. day doesn't exist ).

Note :- is it wat abhra_life gave and ashu corrected? I don't think so.


2. WAP to check month of a yr depending upon user's choice. like da above one.


3. WAP to calculate area of a circle, rectangle & triangle depending upon user's choice.
such as ( if user wants to cal da area of a circle then calculate that, if user wants 2 cal da area of rect then cal that or if user wanna cal da area of tri then do that).


Hey anubhav!

i understud how 2 use if, if-else, but can't understand da use of else-if also wat's da use of

switch?

i know there's a tut but i want it in a familiar lang, in short. very short.


Thanks every1 once again.

Trust me i'll read da tut as i get time.

also i've written all this offline not while being online.



BYE

ANINDYA
Ashis
Ashis #90
Sep 18, 2005 at 6:12 PM
Its hard to believe; People are talking C++ at digit forum!

Great!
Keep It Up! :cool:

Does any one knows PHP very Well or at least fundamentals ??? :wink:
A
Sep 18, 2005 at 7:31 PM
hey incredible difference b/w if else and else if
Code:
if else syntax

if(condition)
{
	statement1;
	statement2;
}
else
{
	statement1;
	statement2;
}

else if syntax	

if(condition1)
{
	statement1;
	statement2;
}
else if(condition2)
{
	statement1;
	statement2;
}
else if(condition3)
{
	statement1;
	statement2;
}

So if else is used when you have to check for only one conidition...
and else if is used where there are multiple condition checks....
Will post the codes soon...
A
Sep 18, 2005 at 7:43 PM
WAP days check
#include<iostream.h>
void main()
{
int day;
cout<<"Enter day :: ";
cin>>day;
switch(day)
{
case 1:
cout<<"Monday";
break;
case 2:
cout<<"Tuesday";
break;
case 3:
cout<<"Wednesday";
break;
case 4:
cout<<"Thursday";
break;
case 5:
cout<<"Friday";
break;
case 6:
cout<<"Saturday";
break;
case 7:
cout<<"Sunday";
break;
default:
cout<<"Wrong Entry";
break;
}
}

Month of the year using switch is same as the above program just add extra cases till twelve and change day names to months..

Area program
#include<iostream.h>
void main()
{
int choice;
double rad,len,width,ba,hei;
cout<<"Enter choice::\n1. for area of circle\n2. for rectangle\n3. for traingle\nAny other to quit\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter radius of circle:";
cin>>rad;
cout<<"\nThe area of circle is "<<3.14*rad*rad;
break;
case 2:
cout<<"\nEnter length of rectangle:";
cin>>len;
cout<<"\nEnter width of rectangle:";
cin>>width;
cout<<"\nThe area of rectangle is "<<len*width;
break;
case 3:
cout<<"\nEnter base of triangle:";
cin>>ba;
cout<<"\nEnter height of triangle:";
cin>>hei;
cout<<"\nThe area of triangle is "<<ba*hei*0.50;
break;
default:
cout<<"Thanks for using...";
break;
}
}
The Incredible
Sep 19, 2005 at 12:22 AM
Thanks anubhav.

THANKS A TRILLION!!!

BTW if possible tel me da use of switch n how does it works.

i understud da use of else-if.

Thanks once again.

Bye.
mohit sharma
Sep 19, 2005 at 1:51 AM
well anubhav i think till now ur problem must had been solve .

and keep moving ahead in life .

best of luck !
and remember ' DIGIT FORUM ke saath rahoge to aise hi aish karoge '.

here u will get many elder brother's precious advice !
QwertyManiac
Sep 19, 2005 at 2:06 AM
a switch statement is a shortened and wiser use of a lot of nested else-if's

It works this way...

switch(choice)
{
case 1:
// When u enter the no. 1 and press enter this is executed.
cout<<"\nEnter radius of circle:";
cin>>rad;
cout<<"\nThe area of circle is "<<3.14*rad*rad;
break;
case 2:
// When u enter the no. 2 and press enter this is executed.
cout<<"\nEnter length of rectangle:";
cin>>len;
cout<<"\nEnter width of rectangle:";
cin>>width;
cout<<"\nThe area of rectangle is "<<len*width;
break;
case 3:
// When u enter the no. 2 and press enter this is executed.
cout<<"\nEnter base of triangle:";
cin>>ba;
cout<<"\nEnter height of triangle:";
cin>>hei;
cout<<"\nThe area of triangle is "<<ba*hei*0.50;
break;
default:
//This statrment shows up if u dont enter a valid number / after the main cases ^^ have been executed.
cout<<"Thanks for using...";
break;//these break statements r perhaps the most vital part of the switch statements.It means that after executing the code of the case specified, stop execution and jump either to the outside/default of the switch statement.
//try not putting these break statements and see what u will get in difference to with it, then u will understand it better.

}
A
Sep 19, 2005 at 5:04 AM
mohit sharma said:
well anubhav i think till now ur problem must had been solve .

and keep moving ahead in life .

best of luck !
and remember ' DIGIT FORUM ke saath rahoge to aise hi aish karoge '.

here u will get many elder brother's precious advice !

hey man i did not have problems... incredible had problems and i waS SOLVING EM..
The Incredible
Sep 19, 2005 at 11:56 AM
correct me was havin probs.

BTW

Thanks every1 for ur so valuable help.

But yet i've not got da code of a program

i'm mentioning it below.

Use of if-else statement:-

6. WAP to read 4 values a, b, c & d from da terminal & calculate da ratio of (a+b) to (c-d) & print da result, if (c-d) is not equal to zero.

Thanks every1 once again.

can't write mor gonna prepare maths for 2morrow.

Rest Assured

Anindya
QwertyManiac
Sep 19, 2005 at 2:18 PM
Code:
#include<iostream.h>
void main ()
{
int a,b,c,d,r1,r2,ratio;
cout<<"\nEnter a";
cin>>a;
cout<<"\nEnter b";
cin>>b;
cout<<"\nEnter c";
cin>>c;
cout<<"\nEnter d";
cin>>d;
r1=a+b;
r2=c-d;
{
if (r2<=0)
{
cout<<"\n c-d is zero, cant continue";
}
else
{
ratio=r1/r2;
cout<<"the ratio is "
cout<<ratio;
}
}

Hope this is right :oops: :d :?:
The Incredible
Sep 19, 2005 at 3:08 PM
me too hop so.

hey anubhav wat do u say?
A
Sep 19, 2005 at 8:10 PM
ya it is fine... just check that if you dont want a negative answer or sometinhg like that then change in the line
if (r2==0) you can change it to... if(r2<=0)/// just it... otherway the program is completely fine...
QwertyManiac
Sep 19, 2005 at 8:18 PM
oops, sorry never thot of it,
EDITED !

Thn for that mistake point anubhav !
The Incredible
Sep 20, 2005 at 3:06 PM
Thanks anubhav!

Thanks qwerty.

qwerty, contact me ASAP
mohit sharma
Sep 25, 2005 at 7:31 AM
sorry anubhav u were mistakenly taken as incredible !
A
Sep 25, 2005 at 7:37 AM
mohit sharma said:
sorry anubhav u were mistakenly taken as incredible !
its not a problem mohit... its just there are so many ppl posting that you take someone for soemone else....
sid_ashok
sid_ashok #105
Sep 25, 2005 at 3:44 PM
Hello Brothers and sisters
this the right thread for me.

Ask me what ever u wana learn.

Any one intrested in graphics in C++ or graphics in Qbasic consult me.

In graphic in c++ u can use your mouse in the program.
and u can alse create window style menus.
U can click on them.
U can draw any thing like ,any thing 3D or 2D( all in C++)
Maverick340
Sep 25, 2005 at 5:24 PM
Code:
#include<iostream.h>
#include<string.h>
#include<stdio.h>

void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;i!='\0';i++)
	{
	if( str[i]=='d'||str[i]=='D')
	 {
	 str[i]='*';
	 str[i+1]='*';
	 str[i+2]='*';
	 }}
cout<<str;
}

This according to loads of you may work.It is right according to the Sumita arora book(class11th).
But wen u try it in TC3.0 or TC 4.5 its dosent work!
Error: the null charcter is a '#' and not '\0'.
I spent i hout jus cuz of this problem!
A
Sep 26, 2005 at 7:02 AM
amanwannalearn said:
Code:
#include<iostream.h>
#include<string.h>
#include<stdio.h>

void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;i!='\0';i++)
	{
	if( str[i]=='d'||str[i]=='D')
	 {
	 str[i]='*';
	 str[i+1]='*';
	 str[i+2]='*';
	 }}
cout<<str;
}

This according to loads of you may work.It is right according to the Sumita arora book(class11th).
But wen u try it in TC3.0 or TC 4.5 its dosent work!
Error: the null charcter is a '#' and not '\0'.
I spent i hout jus cuz of this problem!

'\0' works fine in both TC 3 and 4 and after you said this i tested it... i don;t know why it is not working on your pc
M
mako_123 #108
Sep 26, 2005 at 4:20 PM
can any one please post the program of Tower Of Hanoi .
Maverick340
Sep 26, 2005 at 5:42 PM
amanwannalearn said:
Code:
void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;[b]i!='\0[/b]';i++)
	{
	if( str[i]=='d'||str[i]=='D')

Oh gawd!i am such a dooofus!
the correct code is str[i]!='\0'
and not str[i]!='\0'
When you give str[i]!='\0' it runs the loop 35 times cuz the ACSII code of '\0' is 35.
sorry 
	 :oops:
A
Sep 26, 2005 at 7:34 PM
mako_123 said:
can any one please post the program of Tower Of Hanoi .
Code:
#include<stdio.h>
#include<conio.h>
int LDisc[8],RDisc[8],CDisc[8],lc=0,rc=0,cc=0,nod;
void transfer(int n,char from,char to,char temp,int i);
void Display(int a[],int count,int col);
void main()
{
	int i;
	clrscr();
	printf("Welcome to Tower Of Hanoi Problem!\n");
	printf("How Many Disk ?");
	scanf("%d",&nod);
	for(i=0;i<nod;i++)
	LDisc[lc++]=nod-i;
	clrscr();
	gotoxy(2,2);
	Display(LDisc,lc,2);
	getch();
	transfer(nod,'L','R','C',1);
}
	
	void transfer(int n,char from,char to,char temp,int i)
	{
		if( n > 0 )
		{
			transfer(n-1,from,temp,to,i+1);
			clrscr();
			printf("Move Disk %d from %c to %c \n",n,from,to);
			switch(from)
			{
				case 'L': if(lc)
					  lc--; break;
				case 'R': if(rc)
					  rc--;break;
				case 'C': if(cc)
					  cc--;break;
			}
			switch(to)
			{
				case 'L': LDisc[lc++]=n;
					  break;
				case 'R':RDisc[rc++]=n;
					 break;
				case 'C':CDisc[cc++]=n;
					 break;
			}	
			gotoxy(2,2);
			Display(LDisc,lc,2);
			gotoxy(27,2);
			Display(RDisc,rc,27);
			gotoxy(52,2);
			Display(CDisc,cc,52);
		    	printf("\n");
			printf("Press Any Key For Next Move ");
			getch();
			transfer(n-1,temp,to,from,i+1);
	}
	return;
}
	
void Display(int a[],int count,int col)
{
	int i,j,k;
	for(i=0;i<nod;i++)
	{
		if(count+i ==	nod)
		{
			for(j=nod;j > a[count-1]-1;j--)
			printf(" ");
			for(j=0;j < a[count-1];j++)
			printf("-");
			printf("|");
			for(j=0;j<a[count-1];j++)
			printf("-");
			for(j=nod;j > a[count-1]-1;j--)
			printf(" ");
			count--;
		}
		else
		{
			for(j=0;j<=nod;j++)
			printf(" ");
			printf("|");
			for(j=0;j<=nod;j++)
			printf(" ");
		}
		k=wherey();
		gotoxy(col,k+1);
	}
}
This should work
M
mako_123 #111
Sep 26, 2005 at 9:49 PM
Thanks Anubhav

Have you also got the same program with the help of Linked List .
The Incredible
Sep 27, 2005 at 1:03 AM
Hey wats Tower of Hanoi?

n wats da "amanwannalearn"'s code is all abt?
A
Sep 27, 2005 at 8:56 AM
Sorry man i don't have it for Linked List but ill try to make one and post it..
M
mako_123 #114
Sep 27, 2005 at 12:05 PM
Thank You
Maverick340
Sep 28, 2005 at 2:52 PM
My code is ment to sensor the word dog in a sentece
QwertyManiac
Sep 28, 2005 at 7:36 PM
what do u mean by that, there only one thing up, the sky et all... :p

if u dont understand wat we r talkin, plz read the whole thread...
A
ApoCalypse #118
Sep 28, 2005 at 9:00 PM
@The Incredible
Tower of Hanoi?...

its a simple puzzle
consider 3 pegs a, b, c

let peg a have n disks of varying sizes arranged in descending order from bottom...largest at the base..

c is the destination peg

transfer all disks from a to c subject to the foll conditions...

1) you can use b as an auxillary peg
2) only one disk can be transferred at a time
3) never can a smaller disk be atop a larger one

simple enough??
the implementation is simple as well...think about it
hint: (use recursion to simplify it)
bkpeerless
bkpeerless #119
Sep 29, 2005 at 10:22 PM
from where can i download turbo c++

Please help me in finding the download link of Turbo C++ ..

[Edited Batty]
bkpeerless
bkpeerless #120
Sep 29, 2005 at 10:23 PM
search google
Vishal Gupta
Sep 29, 2005 at 10:46 PM
What is this???????
Question or answer :lol:
godsownman
godsownman #122
Sep 29, 2005 at 11:54 PM
Borland C is available. it is 99.99% same . You can dload it from here.

*www.pitt.edu/~stephenp/misc/downloadTC.html

However if u need TURBO C only then please PM me with ur email and I shall mail it .

Regards
Maverick340
Oct 1, 2005 at 5:15 PM
I wnated help in c++
particularly the for loop,and arrays(2-d)
can anyone help?
A
Oct 1, 2005 at 5:50 PM
amanwannalearn said:
I wnated help in c++
particularly the for loop,and arrays(2-d)
can anyone help?
What kind of help do you need....????
Maverick340
Oct 2, 2005 at 12:04 PM
MAkeing those pyramid programs and i really didnt understand how 2-d arrays work(both string and integers).
A
Oct 2, 2005 at 12:18 PM
so you need ebooks, i think that.. go through yashwant kanetkar's let us c book. Its around 110 rs. cost.. go buy one.. its a must have for all beginners for c
Maverick340
Oct 5, 2005 at 10:53 PM
I hated that book!rubbish!
actually i picked up let us c++.
Found it worthl;ess
S
sakumar79 #128
Oct 5, 2005 at 11:59 PM
i found Bruce Eckels "Thinking in C++" very thorough. Be warned though that it may appear to be a bit challenging to start off with it. You can download it at *www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Arun
aadipa
aadipa #129
Oct 6, 2005 at 12:05 AM
@The Incredible

You wanted the tower of hanoi code

Code:
// Textual Tower Of Hanoi Solution

#include <conio.h>
#include <iostream.h>

enum POLE { LEFT, MIDDLE, RIGHT };
void transfer(int n, POLE from,POLE to, POLE temp);

const char * poles[3] = { "LEFT  ",
			  "MIDDLE",
			  "RIGHT " };

const int MAX_DISK_SIZE = 30;

class Stack {
   public :
      Stack() {
	 toc = 0;
	 }

      ~Stack() {
	 }

      unsigned short length() {
	 return toc;
	 }

      int get() {
	 if(toc == 0)
	    return -1;
	 else
	    return element[toc-1];
	 }

      void pop() {
	 toc --;
	 }

      void push(int i) {
	 element[toc++]=i;
	 }

   private :
      int toc;
      int element[MAX_DISK_SIZE];
   };


Stack Pole[3];

void main(void) {

   int n,i;

   clrscr();

   cout << "\nWelcome to the TOWER OF HANOI program by Ashish Patil"<<endl;
   cout << "\nHow many disks ? ";
   cin  >> n;

   for(i=0;i<3;i++) {
      Pole[i] = Stack();
      }

   for(i=n-1;i>=0;i--) {
      Pole[LEFT].push(i);
      }

   transfer(n, LEFT, RIGHT, MIDDLE);

   cout <<"Process complete. Press any key to exit";

   getch();

   }

void transfer(int n, POLE from, POLE to, POLE temp) {

   if( n > 0) {
      transfer( n-1, from, temp, to);
      cout << "Move disk "<< n
	   << " from " << poles[from]
	   << " to " << poles[to]
	   <<endl;
      transfer( n-1, temp, to, from);
      }
   }

Let me find the code which i made using C graphics... I will post that link too...
aadipa
aadipa #130
Oct 6, 2005 at 12:31 AM
Ok found it.. the code is little big so i will post it only if any1 wants... PM me for that

Here is the executable file *www.sourabh.net/files/tower.exe

It is executable file, just run the file, select no of disks and type of motion, keep in mind, the animation is really slow, but I have kept higher speed for more no of disks...
The Incredible
Oct 6, 2005 at 12:46 AM
aadipa said:
@The Incredible

You wanted the tower of hanoi code

SORRY DEAR!

I DIDNT WANTED IT INSTEAD I ASKED WHAT IS TOWER OF HANOI.
M
mako_123 #132
Oct 6, 2005 at 1:07 AM
Can anyone post the tower oof hanoi created using LInk List.
the_moon
the_moon #133
Oct 6, 2005 at 11:36 AM
Robert Lafore Galgotia Publications.
I remember seeing the code of Tower Of Hanoi in it.. Sorry that I'm unable to provide the code rightnow.
the_moon
the_moon #134
Oct 6, 2005 at 11:40 AM
amanwannalearn said:
I hated that book!rubbish!
actually i picked up let us c++.
Found it worthl;ess

Da Best Book any beginner of C++ can have is Sumita Arora.
Its very simple, yet very very informative. It covers everything from Loops to arrays to Classes to Pointers.

Highly Recommended for beginners! :!:
The Incredible
Oct 6, 2005 at 8:19 PM
well thanks a lot. i rocked my theory n practical exams.

my teacher said i'm da only guy who hav answered 9/10 answers correctly. i did only one wrong question. it was asked to do by switch but mistakenly i did it by else-if.


Thanks Everyone!!!

i'm unable to find da symbol which luks like "II" and means "or" in C++ on my keyboard plz help me.
A
Oct 6, 2005 at 9:58 PM
Good work man.. now you can start learnign C++ and not just taking the codes and writing em down...
Maverick340
Oct 6, 2005 at 10:24 PM
the_moon said:
amanwannalearn said:
I hated that book!rubbish!
actually i picked up let us c++.
Found it worthl;ess

Da Best Book any beginner of C++ can have is Sumita Arora.
Its very simple, yet very very informative. It covers everything from Loops to arrays to Classes to Pointers.

Highly Recommended for beginners! :!:

Dude thats our cource book!!Ya it nice but i dont like it..loads of error and no examples !CRaPPPY book!
A
Oct 7, 2005 at 7:33 AM
YOure in which standard... or in college..??? what???
Thor
Thor #139
Oct 7, 2005 at 11:54 AM
Sumita Arora is the Course Book 4 ISC and CBSE..He must be in 11th/12th .
Try This :
WAP to Display all combinations of a 5 lettered word (No repeatations of letter)

then
WAP to which will check a series of Numbers given then Find out the number which doesn't belong to the series.It will then remove that number and replace it with the correct number.

Savvy??
The Incredible
Oct 7, 2005 at 3:00 PM
anubhav_har said:
Good work man.. now you can start learnign C++ and not just taking the codes and writing em down...

Thanks!!!

I'm havin holiday from day after tomorrow to 13th which is mor than i need read those. I hop i'll know abt it as much as i can within these days.

Bye.
crazybutt
crazybutt #141
Oct 30, 2005 at 6:36 PM
Tc++

well guyz .... i have turbo c installed on my sys wid win XP an wen i try to quit the tc window .........
d monitor just shows a black screen an i am stuck wid it. No attempt to come back to d desktop works... altho d comp is still runnin i.e i can still perform tasks using my keyboard but i cant see anythin on d monitor... i even tried reinstalling but d same problem started to occur after a few dayz of normal working
Plz help........i hav an assgnmt to do an am stuck wid dis problem!!!
Jags
Jags #142
Oct 30, 2005 at 11:25 PM
dont quit the tc window....

instead use ALT+TAB to get to windows and then right click o the tc window to close it

this is a workaround.. and it does...work-around! :p

do remember to delete files with SWP extension in the TC folder though... as an abnormal termination leaves them there
crazybutt
crazybutt #143
Nov 2, 2005 at 1:12 AM
but even if i alt-tab a) it still consumes 99% of CPU time and b)i will eventually hav to restart..............isnt dere a way to correct it somehow??
bharat_r
bharat_r #144
Nov 2, 2005 at 2:16 AM
try tweaking in the compatability mode.
siriusb
siriusb #145
Nov 2, 2005 at 3:57 AM
crazybutt said:
but even if i alt-tab a) it still consumes 99% of CPU time and b)i will eventually hav to restart..............isnt dere a way to correct it somehow??
For the CPU consumption, try this: Create a batch file (.bat extension) and put this in it:
Code:
start /belownormal pathToTC++
Use this bat file to start TCpp and ntvdm will no longer hang the other processes.
mohit sharma
Nov 3, 2005 at 11:17 PM
turbo c++ compilers consumes a lot of cpu time , i always change it's priority using windows task manager and then i can listen music seamlessly , doing programming
lol
J
jitu_mania #147
Nov 10, 2005 at 2:38 PM
borland c and borland c++ to make my projects of my school's

borland c and borland c++ to make my projects of my school's course. from where i can download these programs
S
sakumar79 #148
Nov 10, 2005 at 3:58 PM
Dont think Borland C/C++ is available for free download, but you can use Dev C++ from *www.bloodshed.net/devcpp.html which is a free C++ IDE with Mingw port of GCC (GNU Compiler Collection) as it's compiler

Arun
A
amitsaudy #149
Nov 10, 2005 at 6:44 PM
Try this link

<snipped>


EDIT:No illegal links please-digen
NikhilVerma
Nov 12, 2005 at 9:07 PM
Old is gold says us... :p

A much better option than the 178MB C builder is the 4MB TC...
And he wants to make projects for the school so he'd better use TC coz most of the schools have TC installed...

But I think you should use Dev C++ ...
N
Nov 16, 2005 at 5:51 PM
Simple C++ Query

Code:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
void main()
{
  clrscr();
  char inp[4], out[4];
  int i, len, k;
  cout<<"\n\n-----PROGRAM TO PERFORM POLYALPHABETIC ENCRYPTION-----\n\n";
  cout<<"\nENTER THE STRING TO BE ENCRYPTED: ";
  gets(inp);
  len=strlen(inp);
  for(i=0;i<=len-1;i++)
    out[i] = (int)inp[i] + i + 1;
  cout<<"\n\nTHE ENCRYPTED CIPHER TEXT IS: ";
  puts(out);
  getch();
  return;
}

I tried the above program but the output comes like this

Code:
-----PROGRAM TO PERFORM POLYALPHABETIC ENCRYPTION-----

ENTER THE STRING TO BE ENCRYPTED: DEAR

THE ENCRYPTED CIPHER TEXT IS: EGDVDEAR

The above prgram encrypts like adding position of alphabet in input to its ascii code. DEAR should give EGDV as output.

It always takes length of out string as greater than 4. Strlen on inp always gives 4 but strlen on out gives 8 in this case and on changing 4 to 10 strlen on out increases to 14 also. Why does not length of out remains 4 as specified?

Please Help Me Urgently.........
G
Nov 16, 2005 at 6:34 PM
I think its the encryption logic fault. Since you are encrypting the whole string upto length (0 to len-1) therefore in effect you are also encrypting the null terminating character '/0'. Jst add '/0' after len amount of characters in the encoded out array and i think it will give the correct answer.

Also i can't figure out how the strlen is giving the correct answer for the inp array since u gave input as DEAR(4 character) there's no room left for the null terminating character. Make sure you check the bounds for input coz it might not work when strings are long!!!!.

I'm not an expert on this and i may be wrong but give it a thought!
NikhilVerma
Nov 16, 2005 at 7:27 PM
Code:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
void main()
{
  clrscr();
  char inp[4], out[4];
  int i, len, k;
  cout<<"\n\n-----PROGRAM TO PERFORM POLYALPHABETIC ENCRYPTION-----\n\n";
  cout<<"\nENTER THE STRING TO BE ENCRYPTED: ";
  gets(inp);
  len=strlen(inp);
  for(i=0;i<=len-1;i++)
    out[i] = (int)inp[i] + i + 1;
  out[i]=NULL;
  cout<<"\n\nTHE ENCRYPTED CIPHER TEXT IS: ";
  puts(out);
  getch();
  return;
}


UJLW TJRYQJ IGOT ZQX EGDV ;)
N
Nov 16, 2005 at 8:41 PM
Biggest Problem for me is that same program worked for me on College PC but not working on my home PC. Also I made the length small as with initial length kept at 100 gave such type of output

DCGV@# !....DEAR

Null character is always after len not include in len of string if I got my basics right.
sujithtom
sujithtom #156
Nov 16, 2005 at 9:57 PM
First of all assign the arrays some initial values. Secondly check your complier with the one u use in our college.
Maverick340
Nov 16, 2005 at 10:05 PM
I think this shud be moved here *www.thinkdigit.com/forum/viewtopic.php?t=32408&highlight=
S
satbir #158
Nov 16, 2005 at 10:40 PM
hey your logic is quite ok........... no probs what so ever................. i think the prob lies in the puts function....... i even tried fflush functions to clear the memory but it doesn't work.........i'll try it again .......... in the meanwhile y don't u use an alternative for the puts function.............. this proggy is workin fine

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
void main()
{
clrscr();
char inp[4], out[4];
int i, len, k;
cout<<"\n\n-----PROGRAM TO PERFORM POLYALPHABETIC ENCRYPTION-----\n\n";
cout<<"\nENTER THE STRING TO BE ENCRYPTED: ";
gets(inp);
len=strlen(inp);
for(i=0;i<=len-1;i++)
out = (int)inp + i + 1;
cout<<"\n\nTHE ENCRYPTED CIPHER TEXT IS: ";
for(i=0;i<len-1;i++)
cout<<out;
getch();
}


we use retuern only in case of an in main function............ void function is by default empty so it needn't return any value............ u can skip that
N
Nov 16, 2005 at 11:11 PM
Thanks for the code. It worked.
A
amitsaudy #160
Nov 25, 2005 at 12:55 PM
If hes in school then he should use the msdos based
TC.
Dev CPP is great but for a newbee it can be a little confusing.
puja399
puja399 #161
Nov 25, 2005 at 3:47 PM
amitsaudy said:
....he should use the msdos based
TC.
Is it still alive, MS-DOS ?????? :?:
S
satbir #162
Nov 26, 2005 at 11:56 PM
hey puja............ dos is very much alive.......... many ppl still use it to make partitions(using Fdisk).......
puja399
puja399 #163
Nov 27, 2005 at 12:57 PM
satbir said:
hey puja............ dos is very much alive.......... many ppl still use it to make partitions(using Fdisk).......
So it seems from ur post!!! Nice use for Dos, after all.
Ru sure its Dos-fdisk that many ppl r still using, and not Windows-fdisk????

BTW, fdisk is a NICE(??!!!) tool for partitioning, won't u agree !!!!! :twisted: :twisted: :twisted:
A
amitsaudy #164
Dec 3, 2005 at 7:11 PM
Dear
MS Dos is still used mainly due to the fact that
the Nt based os ie: win2k,Xp etc does not allow any
applications direct and complete access to the hdd and the MBR.
Hence for running app like partion magic etc real dos mode is required.
You also cannot install a boot manager like XOSL through XP.
sujithtom
sujithtom #165
Dec 3, 2005 at 9:13 PM
I think they give away old versions for free. Look their Musume Page
puja399
puja399 #166
Dec 3, 2005 at 10:37 PM
amitsaudy said:
Dear
MS Dos is still used mainly due to the fact that
the Nt based os ie: win2k,Xp etc does not allow any
applications direct and complete access to the hdd and the MBR.
Hence for running app like partion magic etc real dos mode is required.
How very enlightening!!!! Silly me, I didn't know the 'true use' of MSDOS nowadays. Now I know finally, that for NT based OSs, I need MSDOS (?!) to have 'complete' access to hDD and MBR. So, for my XP, I don't need tools like 'diskpart' and also I guess the MS guys were fool enough to add coomands like 'fixmbr' etc, etc.
amitsaudy said:
You also cannot install a boot manager like XOSL through XP.
I don't know about XOSL, but I guess that the bootmanager installed on my XP partition, what is its name ? Oh, yes, VCOM System Commander, that is (I think) installed in my HDD is just an imagination of mine. Its actually not there, I think its there, but its not, its because of The Matrix :p :p :p
sujithtom
sujithtom #168
Dec 4, 2005 at 6:30 AM
Guys the best C++ IDE and complier around is of Dev CPP. Its IDE allows you to use write in 3-4 programming languages like C, C++, GTK etc. I agree we can write C in any C++ program. Then its complier is GCC the best one. Even NASA people are using it!
P
pradeep #169
Dec 31, 2005 at 12:59 PM
C++ installation

I have copied c++ folder to c: drive. But cpp.exe is not opening. How to install c++ in c: drive ?
S
shwetanshu #170
Dec 31, 2005 at 1:22 PM
i think... the file located in tc\bin\tcc.exe shud be used to run the program
nix
nix #171
Apr 30, 2006 at 10:42 AM
need turbo c++ 3.0 IDE

hi all,
i need turbo c++ 3.0 IDE...the same version is there in my college lab comps. i need that version of c++. i searched the net but couldnt find that version. can anyone give me the link of where its available.
thanks in advance
william
william #172
Apr 30, 2006 at 1:29 PM
Re: need turbo c++ 3.0 IDE

But why do u want to go for turbo c++ why don't u try out bloodshed dev tools for c++.
saurabh.sauron
Apr 30, 2006 at 1:35 PM
Re: need turbo c++ 3.0 IDE

u could download it via Bittorrent if it is available for free.

why not take it from the college itself???
MysticHalo
MysticHalo #174
Apr 30, 2006 at 3:39 PM
Re: need turbo c++ 3.0 IDE

saurabh.sauron said:
why not take it from the college itself???

Quite right...probably the simplest solution.
TurboC++ is a product of Borland, so better check their site. AFAIK, now Borland has discontinued TurboC++ and offers only the command line compiler for C++.
actually, there r two types--DOS IDE and WINdows IDE...i think u might find the DOS one,but windows it not available at all.

PS: i dont understand why most of colleges and schools stick to Turbo even after its no longer available.
sms_solver
sms_solver #175
Apr 30, 2006 at 4:16 PM
Re: need turbo c++ 3.0 IDE

I don't thing Turbo C++ 3.0 is free,

Turbo C++ v1.01 free and it can be download from Borland
Link:
*community.borland.com/article/0,1410,21751,00.html
nix
nix #176
Apr 30, 2006 at 7:59 PM
Re: need turbo c++ 3.0 IDE

i have the 1.01 version dos IDE..i was looking for version 3. anywayz, i guess i'll have to take it from the college itself.
thanks,
saurabh.sauron
Apr 30, 2006 at 8:33 PM
Re: need turbo c++ 3.0 IDE

@nix,
if u want an interface similar to Turbo C++ IDE, u can download a free version of it labelled Turbo C++ Lite. I use it along with Bloodshed.

Download Link :-

*www.simonhuggins.com/courses/progbegin/c/download/TCLITE.exe
ashfame
ashfame #178
Apr 30, 2006 at 8:43 PM
Re: need turbo c++ 3.0 IDE

do ya know when running turbo c++ 3.0 IDE, cpu usage jumps to 100%.
varkey
varkey #179
May 1, 2006 at 12:23 AM
Re: need turbo c++ 3.0 IDE

anyway if u want TC++ 3.0. i can send it to u. just mail me at admin{at}varkey.info
Nimda
Nimda #180
May 1, 2006 at 11:40 AM
Re: need turbo c++ 3.0 IDE

Version 3.0 is discontinued by Borland. But it's easy to find it. Just google for "tc30.exe".
aneesh kalra
Feb 15, 2007 at 9:05 PM
c++

Code:
while(i<3){
if(tc[i]==c,c,c)
flag=1;
Here i have referred to c as a char variable which is checked whether it contains another char variable p1 or p2 which hold the symbols of the two players in this game respectively.However c++ shows syntax error when I declare c as a char variable.how can i execute this piece of code.Actually it saves me the hassle of writing two seperate check functions for player 1 and player 2 .
Here is the complete code for my tic tac toe game .
Code:
//Program to run game tic toe
#include<iostream.h>
#include<conio.h>
char player1,player2;
int i=0,j=0,x=0,y=0;
char tc[3][3];
char p1,p2;
int flag=0;
void display(char )
{
for(;i<3;i++)
{
for(;j<3;j++)
cout<<tc[i][j];
}}
void check(char ,char )
{
while(i<3){
if(tc[i]==c,c,c)
flag=1;
}
while(j<3){
if(tc[j]==c,c,c)
flag=1;
}
while(i<j){
if(tc[i][j]==c,c,c)
flag=1;
}
while(i==j){
if(tc[i][j]==c,c,c)
flag=1;
}
if(flag==1){
if(c==p1){
cout<<player1<<"\t has won the game";
}
if(c==p2){
cout<<player2<<"\t has won the game";
}}}
void pos(int i,int j,char c)
{
tc[i][j]=c;
if(i>3,j>3,tc[i][j]!='\0')
cout<<"\n Invalid choice";
}
void initialize(char )
{
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
tc[i][j]='A';
}}
void main(){
cout<<"Welcome to the world of tic toe gaming"<<"\n  Program design and compilation by Aneesh";
cout<<"\n Please enter your names player 1 and player2 in that order";
cin>>player1>>player2;
cout<<"\n"<<player1<<"\t please enter you symbol of choice ";
cin>>p1;
cout<<"\n"<<player2<<"\t please enter your symbol of choice ";
cin>>p2;
while(flag!=1)
cout<<"\n"<< player1<<"\t please specify the position in terms of x and y where you want to place your symbol alongiwth it;ie; your symbo";
cin>>x>>y;
display(tc[3][3]);
pos(x,y,p1);
check(p1, tc[3][3]);
cout<<"\n"<<player2<<"\t please  specify the position in terms of x and y where you want to place your symbol alongwith it ;i.e;your symbol";
cin>>x>>y;
display( tc[3][3]);
pos(x,y,p2);
check(p2,tc[3][3]);
cout<<"\n Thank you for playing tic toe with us";
getch();
}
n2casey
n2casey #182
Feb 15, 2007 at 9:36 PM
Re: c++

As I think, multiple conditions in if() r give by using && or || operator.

&& is for condition of AND, and || is for condition of OR
e.g.
if (x>3 && y<7) means, if x greater than 3 and y less than 7

while
if (x>3 || y<7) means, if x greater than 3 or y less than 7
aneesh kalra
Feb 16, 2007 at 12:47 PM
Re: c++

actually the problem here is the variable within variable thing.I was asking whether this can be done or not.
mediator
mediator #184
Feb 16, 2007 at 2:20 PM
Re: c++

I think there's a syntax error in this code!

There r many problems that I can see
1. One is as pointed my @n2casey (syntax error)
2. while is a loop. You have not put any increment in it!
while(j<3){
if(tc[j]==c,c,c)
flag=1;
This wud mean "if (tc[0]==c)", checking infinite times as j is equal to zero always (no increment).

3. Many Incorrect bracket's pairings.

aneesh_kalra said:
actually the problem here is the variable within variable thing.I was asking whether this can be done or not.
Variable within variable?? Means?
aneesh kalra
Feb 16, 2007 at 10:36 PM
Re: c++

The problem that I have stated about which I was confused was whether the aray could be checked for the variable fro within it;i.e; if i can check whether c has the value of p1;ie; player 1's symbol.Would using a reference variable be helpful.
.Can you please be more specific I understood the while thing missed it out but as far I know the brackets were correct.Your valuable guidance in the same will be higly appreciated.
mediator
mediator #186
Feb 16, 2007 at 11:20 PM
Re: c++

Ah yes brackets r correct => my fault!

As for ur problem I'm still not clear what exactly u wanna ask. Neways an array stores values not variables!
n2casey
n2casey #187
Feb 16, 2007 at 11:23 PM
Re: c++

Yes, just take a look at what mediator & I have told u. Made those corrections & plz tell clearly what u want.
romeo_8693
romeo_8693 #188
Feb 17, 2007 at 1:40 PM
Re: c++

i dint get why it is c,c,c?isnt it shud be just a single c?
coolboy_n
coolboy_n #189
Feb 18, 2007 at 1:18 AM
Re: c++

hi everyone,
using 'if(tc[j]==c,c,c)' is perfectly acceptable..

it'll be equivalent to if(tc[j]==c)

also...using a char variable will give u an error here....try using the ascii codes for those characters and put them into individual elements of the array..when u need the character-equivalents ..simply type-cast them.
I hope this'll do..!!
ilugd
ilugd #190
Feb 18, 2007 at 1:40 AM
Re: c++

, yeah, but those 2 extra c's are redundant. right?
n2casey
n2casey #191
Feb 18, 2007 at 1:58 AM
Re: c++

@ coolboy_n

It's acceptable but not work like that. Just run this prog & u will come to know that.
Code:
#include<iostream.h>
void main()
{
char c0, c1='d', c2='f', c3='g';
cout<<"Press key"<<endl;
cin>>c0;
if(c0==c1,c2,c3)
cout<<"Good : "<<c0<<endl;
else
cout<<"Bad : "<<c0<<endl;
}
& here is the output

*img58.imageshack.us/img58/4228/44886068ab7.jpg
*img58.imageshack.us/img58/630/55770532po5.jpg

coz the condition if() will always b true.
aneesh kalra
Feb 18, 2007 at 5:03 AM
Re: c++

thanks for solving my query as here we are checking whether the array contains c1 ,c2 and c3 and not the charcter contained in c1.
Can it be done like this where cis an array
for(i=0;c!='\0';i++)
if(c=='c')
romeo_8693
romeo_8693 #193
Feb 18, 2007 at 11:42 AM
Re: c++

how about:
Code:
for(i=0;i<3;i++)
if(c[i]=='c')
ilugd
ilugd #194
Feb 18, 2007 at 12:16 PM
Re: c++

ah! eureka!!! <running out of the bath naked>
Understood the problem now.
mediator
mediator #195
Feb 18, 2007 at 12:36 PM
Re: c++

aneesh kalra said:
thanks for solving my query as here we are checking whether the array contains c1 ,c2 and c3 and not the charcter contained in c1.
Can it be done like this where c is an array
for(i=0;c!='\0';i++)
if(c=='c')

That wud mean c[1] to c[3] are being checked for value "c". If the array contains "values" c1,c2,c3 it wud return false when being checked for "c".

If u wanna check for a variable, then u shud check for its value. If u wanna compare array value, thenu shud check for its position and the value at that position. Checking array for "variable" cannot be done AFAIK coz variables contains values and array is a kind of variable!
speedyguy
speedyguy #196
May 9, 2008 at 8:49 PM
Turbo C/C++ graphics distorted

prgms r all running fine except wen i use graphics.h n use initgraph d output screen comes distorted....is thr any graphics driver issue....cuz othr graphics suckin appl r running absolutely fine....

cn i use any other compiler if no soln 2 dis...if yes any downloads available....
ps: i cant afford 2 use diff commands in case of compiler change..

waiting fr resp....urgently needed....hv grphcs pgming this semester fr project

thanx...

Enjoy~!
Kl@w-24
Kl@w-24 #197
May 9, 2008 at 9:55 PM
Re: Turbo C/C++ graphics distorted

Could u plz paste the graphics initialization code dat u r using in ur program?
speedyguy
speedyguy #198
May 9, 2008 at 11:37 PM
Re: Turbo C/C++ graphics distorted

none of d graphic related commands execute thr....one f samples pasting here...

#include<iostream.h>
#include<conio.h>
#include<graphics.h>

void main()
{
int i,dx,dy,xa,ya,xb,yb,stp;
int gd=DETECT,gm;
float xincr,yincr,x,y;
initgraph(&gd,&gm,"");
clrscr();
cout<<"\n\tEnter starting co-ordinate-(x,y) ";
cin>>xa>>ya;
cout<<"\n\tEnter ending co-ordinate-(x,y) ";
cin>>xb>>yb;
dx=xa-xb;
dy=ya-yb;
if (dx>dy)
stp=dx;
else
stp=dy;
x=xa;
y=ya;
xincr=dx/stp;
yincr=dy/stp;
putpixel(x,y,4);
for (i=1;i<=stp;i++)
{
x=x+xincr;
y=y+yincr;
putpixel(x,y,4);
}
getch();
}


Enjoy~!
Kl@w-24
Kl@w-24 #199
May 9, 2008 at 11:43 PM
Re: Turbo C/C++ graphics distorted

U need to provide the path to the gfx driver within " and " in:
Code:
initgraph(&gd,&gm,"");

Like this:
Code:
initgraph(&gd,&gm,"c:\\progra~1\\tc\\bgi");

Replace the path to the BGI folder with ur own, keeping the \\ intact. Try it.
speedyguy
speedyguy #200
May 10, 2008 at 10:34 AM
Re: Turbo C/C++ graphics distorted

k tryin dat...

Enjoy~!
speedyguy
speedyguy #201
May 10, 2008 at 10:39 AM
Re: Turbo C/C++ graphics distorted

no sir...no change yet...can thr b any graphics driver issue...coz iv just installed xp aftr removing vista n got all drivers from net....somhow i managed 2 get nvidia 6150 drivers...games n others working fine....n ya 1 mr issue is thr related 2 driver....wen my monitor (laptop) goes 2 sleep on recovering windows screen also gets choppy until i restart it...

Enjoy~!
j1n M@tt
j1n M@tt #202
May 10, 2008 at 10:47 AM
Re: Turbo C/C++ graphics distorted

In ur TC installed folder u will find a BGI directory or folder. In dat folder u will find a EVGA driver file named EGAVGA.BGI . Copy this file to the BIN directory and run the pgm, it will work fine........
Kl@w-24
Kl@w-24 #203
May 10, 2008 at 10:51 AM
Re: Turbo C/C++ graphics distorted

Is it an LCD screen u r working on, I mean, r u using TC on ur laptop? The gfx routine has some issues with LCD screens I think... BTW, plz paste the modified code as well.
Zeeshan Quireshi
May 10, 2008 at 11:02 AM
Re: Turbo C/C++ graphics distorted

*www.thinkdigit.com/forum/showthread.php?t=65520&highlight=ditch
[xubz]
[xubz] #205
May 10, 2008 at 11:59 AM
Re: Turbo C/C++ graphics distorted

@Zeeshan I really don't think you can program DOS based graphics apps without TC.. Both dos.h and graphics.h are unavilable/severely stripped down in BCC 5.1..

Many Colleges _still_ teach Graphics Programming using Turbo C++ these days :-\
speedyguy
speedyguy #206
May 10, 2008 at 12:04 PM
Re: Turbo C/C++ graphics distorted

@j1n M@tt: act sub folders doesnot exist....they r all bundled under main tc folder....object n library directories also targetted at c:\....\tc

@abh1shek: code is now like this...


#include<iostream.h>
#include<conio.h>
#include<graphics.h>

void main()
{
int i,dx,dy,xa,ya,xb,yb,stp;
int gd=DETECT,gm;
float xincr,yincr,x,y;
initgraph(&gd,&gm,"C:\\Arena\\Turboc3\\");
clrscr();
cout<<"\n\tEnter starting co-ordinate-(x,y) ";
cin>>xa>>ya;
cout<<"\n\tEnter ending co-ordinate-(x,y) ";
cin>>xb>>yb;
dx=xa-xb;
dy=ya-yb;
if (dx>dy)
stp=dx;
else
stp=dy;
x=xa;
y=ya;
xincr=dx/stp;
yincr=dy/stp;
putpixel(x,y,4);
for (i=1;i<=stp;i++)
{
x=x+xincr;
y=y+yincr;
putpixel(x,y,4);
}
getch();
}

n using a tablet pc from hp...wit amd64*2, nvidia geforce go6150


@zeeshan: m using ur relo soln but ts not including graphics.h header...
Enjoy~!
Kl@w-24
Kl@w-24 #207
May 10, 2008 at 12:32 PM
Re: Turbo C/C++ graphics distorted

Make it:

Code:
initgraph(&gd,&gm,"C:\\Arena\\Turboc3[b]\\BGI[/b]");
speedyguy
speedyguy #208
May 10, 2008 at 1:24 PM
Re: Turbo C/C++ graphics distorted

r u sure....thr isnt any directory called bgi within turboc3...newez meanwhile m tryin

Enjoy~!

Edit:

no sir...still not working...sorry

ps: m using relo + borland as suggested by zeeshan but graphics.h not working....infact not present in include n lib folder in borland

Enjoy~!
Kl@w-24
Kl@w-24 #209
May 10, 2008 at 2:06 PM
Re: Turbo C/C++ graphics distorted

Extract this BGI folder into ur TC directory and try again.
speedyguy
speedyguy #210
May 10, 2008 at 2:33 PM
Re: Turbo C/C++ graphics distorted

guys plz consider foll codes...this one is workin fine at output screen....nly thing on coming back 2 editor the screen gets distorted....neva d less atleast i got o/p but again wats d diff wit this one



#include"conio.h"
#include"graphics.h"

void main()
{
int gd=DETECT,gm;
initgraph(&gd, &gm, "c:\\arena\\turboc3");
circle(300,150,100);
getch();
closegraph();
restorecrtmode();
}

ps: i found ts no use of borland compiler...they wont support graphics.h
turbo is d only soln

Enjoy~!
Kl@w-24
Kl@w-24 #211
May 10, 2008 at 3:52 PM
Re: Turbo C/C++ graphics distorted

Try removing the restorecrtmode(); line.
T
May 10, 2008 at 4:28 PM
Re: Turbo C/C++ graphics distorted

damm what is wrong with people here? just download and install bloodshed for windows or geany for linux and get done with it!!

all these people trying to make a prehistoric piece of software work is just wrong!

why are u stuck to something which was made in like 1990 just because others use it? pffft..
speedyguy
speedyguy #213
May 10, 2008 at 5:07 PM
Re: Turbo C/C++ graphics distorted

removing restore command not working....

2ndly, that bgi archive not working....says its corrupt...

3rd....trying bloodshed if possible

Enjoy~!
Kl@w-24
Kl@w-24 #214
May 10, 2008 at 6:27 PM
Re: Turbo C/C++ graphics distorted

The BGI archive is alright, I just downloaded it!!
dheeraj_kumar
May 10, 2008 at 7:54 PM
Re: Turbo C/C++ graphics distorted

Offtopic, but he actually installed latest nvidia drivers so he could run BGI graphics... I salute you man, you just redefined the meaning of "graphics card".
speedyguy
speedyguy #216
May 10, 2008 at 9:17 PM
Re: Turbo C/C++ graphics distorted

@dheeraj: thank you

will try bgi again but i guess tats not issue....bgi files r present only thing they aint in seperate folders...al mixed up

Enjoy~!
dheeraj_kumar
May 10, 2008 at 10:42 PM
Re: Turbo C/C++ graphics distorted

Er... speedyguy, I was being sarcastic.
speedyguy
speedyguy #218
May 10, 2008 at 11:06 PM
Re: Turbo C/C++ graphics distorted

i was too dude....sorry fr being ignorant 2 ur sarcasism but may be aftr gettin my things resolved i'll join u....

Enjoy~!
gary4gar
gary4gar #219
May 11, 2008 at 12:46 AM
Re: Turbo C/C++ graphics distorted

Did you try Dosbox?

An open source DOS emulator for BeOS, Linux, Mac OS X, OS/2, and Windows. Primarily focuses on running DOS Games.

I am using this for running TC in Ubuntu. I believe there is a windows port also.
It runs DOS programs very well with alomost zero configrations.

It even runs those 16bit games, which stopped running since Windows NT
Krazy_About_Technology
May 11, 2008 at 1:27 AM
Re: Turbo C/C++ graphics distorted

Dude, remove the clrscr() from there and put cleardevice() inplace of it. Also at the end of program call restorecrtmode() after calling closegraph(). That will help i think. And that BGI directory stuff won't matter. I have seen people having two types of installation of TC++, one that contains all the files in the same dir and other which contains files in different subdirectories. Both versions work fine as long as path is set right at all the places. so if you have all the files in, say, c:\tc then specifying c:\\tc in initgraph will work, provided that the driver file egavga.bgi is present in the directory.

I hope this clear things up for everyone. Correct me if i am wrong somewhere :)
dheeraj_kumar
May 11, 2008 at 9:03 AM
Re: Turbo C/C++ graphics distorted

Were you? I thought you were never sarcastic.

Oh, I think you are being sarcastic.:confused: Because I am most of the times.

All right, lets stop this now, I dont want to spam this thread with more offtopic stuff.
speedyguy
speedyguy #223
May 14, 2008 at 5:23 PM
Re: Turbo C/C++ graphics distorted

@Krazy_About_Technology : placing cleardevice() is not bringing up the output screen...it compiles n remain at editor screen....restorecrtmode is kept aftr closegrph function...

Enjoy~!
K
khattam_ #224
May 28, 2008 at 8:01 PM
Re: Turbo C/C++ graphics distorted

I used TC Graphics for my Galaxian-Like game for the 1st sem project in C..

This sem (3rd) we decided to code Mario .. no wonder it was barely possible to scroll the screen and load bitmaps and all.. So went for Allegro Gaming Library... It has a manual and examples.. Mario is almost complete...

I suggest u to dump TC graphics and use Allegro..
speedyguy
speedyguy #225
Jun 7, 2008 at 2:33 PM
Re: Turbo C/C++ graphics distorted

can u tel me if thrs diff betn allegro, bloodshed n tc as far as coding is concerned...coz i know coding via tc only....

Enjoy~!
speedyguy
speedyguy #226
Sep 15, 2008 at 8:36 PM
Re: Turbo C/C++ graphics distorted

hi again,

time has come for me now 2 get in2 graphics for my projects n i still havnt got rid of my issues....plz help me out if thrs an alternative 2 turbo c++ fr graphics...iv tried borland visual but no help as yet...

m posting a proper detail of wat issues m facing wit visuals...plz take a carefull look...

this is on editor windows(turbo c++) wit a dda/bresenham program for linedraw-
*img165.imageshack.us/img165/2174/img1350vq4.th.jpg

this is now into output screen wich is already seen distorted....try 2 read..."enter end points ......... "
*img155.imageshack.us/img155/7357/img1352ac3.th.jpg

this is aftr providing the inputs...u can see d required line but again its distorted at top...it cn b randomly anywhr...
[img=*img403.imageshack.us/img403/2959/img1353wf8.th.jpg]

and now back 2 editor window...eew! can u even see anything....ts all messed up....dunno wat d hecks wrong...
*img165.imageshack.us/img165/8780/img1354xw2.th.jpg

more observations - wen i press alt-enter aftr this 2get 2 windowed screen it gets back 2 normal wit d editor window.....

as soon as i use initgraph....the screen behaves like this.....

my system is (again)-

amd turion64 X2 1gb ddr2,
nVidia geforce go 6150,
hp pavilion tablet pc (tx1000 series)
12" lcd screen...

thanx,

Enjoy~!
speedyguy
speedyguy #227
Oct 5, 2008 at 6:59 PM
Re: Turbo C/C++ graphics distorted

hi plz reply if any small idea u have...

thrs one more observation i saw....thr problem is not wit my coding....ts wit my DOS graphics....even other Dos based games r not working in ma system....

Enjoy~!
T
tusharmath #228
Oct 31, 2008 at 1:22 AM
Re: Turbo C/C++ graphics distorted

ive been experiencing d same problem...
ive got d same Geforce 6150
its exactly d same... hve been trin all sorts line drawing/clipping algo's ... none of my graphics programs r wrkin fine... may b its a hardware issue...
hve exams comin closer day by day... nd ders no place to practice

do u hve ny alternative 4 dis?
speedyguy
speedyguy #229
Oct 31, 2008 at 7:19 PM
Re: Turbo C/C++ graphics distorted

thrs no issue wit bgi graphics in c++....the graphics in dos is screwed up wit ur system....mine too.....try dos based games even they wont work...

try booting in safe mode wit command prompt n c if it can work wit c++...

else use DosBox Emulator.....that shud work...

Enjoy~!
zegulas
zegulas #230
Nov 4, 2008 at 9:42 PM
Re: Turbo C/C++ graphics distorted

@speedguy did DosBox worked for you?
speedyguy
speedyguy #231
Nov 5, 2008 at 1:02 PM
Re: Turbo C/C++ graphics distorted

ya dosbox worked fine...but it reduces executing speed....so not gettin exact idea abt its speed wit other systems...

Enjoy~!
garfield_56
Nov 25, 2008 at 8:26 PM
Turbo C/C++ and other junk compilers discussions and queries here

hey all,
m learnin c++...i wantd to ask wat is the role og "getch()" in a program.....
i mean most of the programs mentioned in buks nd even on websites don't have a "getch" wriiten before closing main()....but i hv seen dat to get d desired result....i always have to add dis......

why is dis so?? nd is it necessary????
Faun
Faun #233
Nov 25, 2008 at 8:53 PM
Re: getch() in c++

turbo c require getch() and ansi c compilers don't. Find out why ? Just do it and see for yourself
garfield_56
Nov 25, 2008 at 9:03 PM
Re: getch() in c++

turbo c require getch() and ansi c compilers don't. Find out why ? Just do it and see for yourself



ok...i am using turbo c..((seems like m a total newbie))...

if i may ask...:confused:......y do v use so many diff compilers (borland, ansi, turbo,etc...)???
red_devil
red_devil #235
Nov 25, 2008 at 9:05 PM
Re: getch() in c++

hey all,
m learnin c++...i wantd to ask wat is the role og "getch()" in a program.....

did u google ??

but i hv seen dat to get d desired result....i always have to add dis......

are u sure ?? did u try to see what happens when u dont add getch() to your program ??
M
mrintech #236
Nov 25, 2008 at 9:08 PM
Re: getch() in c++

getch() is used for obtaining the desired output

Try removing any of the header file iostream.h and conio.h and see which header file supports getch() ;)
garfield_56
Nov 25, 2008 at 9:23 PM
Re: getch() in c++

are u sure ?? did u try to see what happens when u dont add getch() to your program ??[/quote]




yup...i did......


wen i 5run d progrm (a normal & simple c++ prog..) a blank screen appears for 2-3 sec nd then it goes bak to my program screen....
red_devil
red_devil #238
Nov 25, 2008 at 9:47 PM
Re: getch() in c++

^^ so see.. now u know what the use of the getch() is in your program...


anyways, basically, getch is used to single-byte character from the terminal ... so once u add getch, your output screen waits for you to enter a key (which normally is the enter key)
so once u hit enter, the screen is no longer there.

btw, when u dont add getch(), it doesn't mean that your program isn't correct or anything...only your output window doesn't wait for you to take your own time to read all the output that you get...

hope now u've understood what the use of getch() is.

and btw, use system("pause") instead of getch() and check out what happens :D
QwertyManiac
Nov 25, 2008 at 9:47 PM
Re: getch() in c++

This thread was not supposed to have so many posts, damn you T159! It doesn't have anything to do with ANSI/non-ANSI :p

getch - get a single-byte character from the terminal.

When you call getch() (A Windows Platform-only function), it goes into an input event loop and waits for a single character to be entered (and pressed). And it stores that character into a variable, or discards it if you haven't provided one, like in these cases:
Code:
#include <iostream.h>
#include <conio.h>

void main() {
char c;
c = getch(); // Gets and stores a user-input character
cout << c << endl;
cout << "Press any key to exit.";
getch(); // No variable, used to get into an input-event loop.
}

Input-loop as in it goes into a wait-for-user-to-press-a-key mode. You can see it like the behaviour of some applications that say "Press any key to continue...".

garfield_56 said:
wen i 5run d progrm (a normal & simple c++ prog..) a blank screen appears for 2-3 sec nd then it goes bak to my program screen....

When Turbo C runs a program for you, it returns to the editor immediately after the program exits a.k.a the end of main(). So it will appear like your program has started and terminated all of a sudden after your input is given.

As you yourself said, "to get the desired result" which here, is to wait for the user to see the final output, we use a getch(). To give that "Press any key when you have seen the output and exit" effect. Thats all there is to its use in Turbo C programs.

If you ran your compiled program via normal DOS mode, you won't need this feature.

For an example, try running a program without a clrscr() function. You will see the old successful output (upon successive runs), meaning it has nothing to do with the program's working.

garfield_56 said:
if i may ask.........y do v use so many diff compilers (borland, ansi, turbo,etc...)???
You do know compilers are platform-dependent and also architecture-dependent. Code might not be but compilers are. Thus, there came out several multi-featured platform-specific compilers after the C++ language was developed. These specialized compilers like borland aimed to provide good pre-built libraries for programmers to use.

The standard compiler (like ANSI) contains only those functions that can run across all platforms, from OSX to Linux. These specialized compilers come for one specific platform, like Borland for Windows. And they provide Windows-usable special functions, of which things like getch() are a part of.

For learing, using a standard compiler (GNU C Compiler for example) is the best practice, so that what you learn is all things standard (works across all OS) and you won't develop dependence on some particular OS-specific function like getch(). This is but one of the many reasons why people keep recommending them.

Note: Do read my entire post. Not this line alone.
red_devil
red_devil #240
Nov 25, 2008 at 9:51 PM
Re: getch() in c++

^^ now that is one detailed explanation :D

btw, i read half your post and of course the last line :D
Faun
Faun #241
Nov 25, 2008 at 9:56 PM
Re: getch() in c++

add getche() too :D
garfield_56
Nov 25, 2008 at 10:00 PM
Re: getch() in c++

thnx....:cool:

u mean to say dat getch() is used to display d output for d user----if we don't use it, den although d program will run, but d output will not be displayed???did i get it right??




and ya...in d program u gave
Code:
#include <iostream.h>
#include <conio.h>

void main() {
char c;
c = getch(); // Gets and stores a user-input character
cout << c << endl;
cout << "Press any key to exit.";
getch(); // No variable, used to get into an input-event loop.
}


r we usin getch() to do wat cin>> does(i.e.--get d input 4m user)??
QwertyManiac
Nov 25, 2008 at 10:06 PM
Re: getch() in c++

thnx....:cool:

u mean to say dat getch() is used to display d output for d user----if we don't use it, den although d program will run, but d output will not be displayed???did i get it right??

No! The output is displayed just fine, but too fast and since the program ends after showing last cout operation, Turbo C comes back on the screen. So it appears like no output is shown, while it is. Just that it happens very fast and you don't notice.

You can use cin to the same effect but the difference is that using getch() does not echo (show) the pressed character on the screen. If you use cin, you can see what you are giving as an input but with getch() you can't. This is advantageous in certain situations.
M
mrintech #244
Nov 25, 2008 at 10:08 PM
Re: getch() in c++

Here something for you Mr. Garfield: *www.planet-source-code.com/vb/Tutorial/default.asp?lngWId=3
garfield_56
Nov 25, 2008 at 10:12 PM
Re: getch() in c++

thnx Qwerty.....i finally got it all cleared!!! :cool::):grin:

Here something for you Mr. Garfield: *www.planet-source-code.com/vb/Tutorial/default.asp?lngWId=3



nice page--thnx 2 u 2!!:)
Faun
Faun #246
Nov 25, 2008 at 10:18 PM
Re: getch() in c++

^^switch to some other good compiler. If it's compulsory due to college then bear with the agony and pain of coding in Turbo C++ :D
garfield_56
Nov 25, 2008 at 10:28 PM
Re: getch() in c++

^^switch to some other good compiler. If it's compulsory due to college then bear with the agony and pain of coding in Turbo C++ :D



hey....i've just started learning c++....till now..i dint hav much problm wid turbo...
QwertyManiac
Nov 26, 2008 at 12:31 AM
Re: getch() in c++

hey....i've just started learning c++....till now..i dint hav much problm wid turbo...
Yes but the compiler and the language you are using was what existed in late 1980s. That's even before Jurassic age at the rate technology develops. Modern compilers provide better binaries, useful error and warning messages and even allow for easy use of new elements of the programming languages - like namespaces in C++. Its always good to use something new.
redhat
redhat #249
Nov 26, 2008 at 8:02 PM
Re: getch() in c++

Thats the problem! Our colleges use stuff that is way too outdated
Certain valid syntax's are just not accepted by TC, its too frustrating, a few days back i fought with my professor as to why were we so outdated, learning C++ on turbo C and then doing VB 6.0 instead of .net
garfield_56
Nov 26, 2008 at 8:04 PM
Re: getch() in c++

Yes but the compiler and the language you are using was what existed in late 1980s. That's even before Jurassic age at the rate technology develops. Modern compilers provide better binaries, useful error and warning messages and even allow for easy use of new elements of the programming languages - like namespaces in C++. Its always good to use something new.



yo...Lemme put it dis way...m learnin c++ in my school (yeah--no college yet!!:p)..
and its Turbo there..But yes, as soon as I master it, I'll surely go in for other compilers, coz as u said ""Its always good to use something new"":cool::)
ajooba215
ajooba215 #251
May 6, 2009 at 8:22 PM
turbo c for xp 64 bit...

hey guys ..m unable to 'run turbo c' on ma 64 bit version of windows xp....got any solutions for it?
P
paroh #252
May 6, 2009 at 9:50 PM
Re: turbo c for xp 64 bit...

See my this post (VIDEO Tutorial is also uploaded) how to set the setting to make the turboc run
Code:
*www.thinkdigit.com/forum/showthread.php?t=103652&highlight=dosbox
sky90
sky90 #253
Sep 12, 2010 at 11:41 AM
Turbo C in Windows 7

Any one can plz provide me turbo c working in windows 7.
papul1993
papul1993 #254
Sep 12, 2010 at 2:51 PM
Re: c for window 7.

get dosbox and try to run it there
S
sny #255
Sep 14, 2010 at 1:11 PM
Re: c for window 7.

on 64 bit rite? I tried, but couldn't get it done. And now I'm using Visual Studio 2010..
veddotcom
veddotcom #256
Oct 8, 2010 at 2:17 AM
Re: c for window 7.

I m running turbo C++ Compiler on Windows 7 x64... with the help of DOSBOX
manaskumar
manaskumar #257
Oct 8, 2010 at 9:34 PM
Re: c for window 7.

Write your programs in any suitable editor and complie it with GCC.
I personally use ECLIPSE IDE and DEVC++.
cute.bandar
Oct 8, 2010 at 9:51 PM
Re: c for window 7.

There's also tiny c compiler. a no frills simple to use compiler.
It should work windows 7
L
Oct 14, 2010 at 6:30 PM
Re: Turbo C in Windows 7

use it with dosbox
Who
Who #260
Oct 15, 2010 at 9:06 AM
Re: Turbo C in Windows 7

Here what you should do , step by step

1) Show the finger to your teacher.
2) Burn that filth called "Let Us C" or any other indian author book.
3) Refer to this tutorial for books & compiler to use
*www.thinkdigit.com/forum/developers/132924-c-c-beginners-guide-post-basic-questions-here.html
4) Use the gcc compiler for betterment of yourself & the firm which will hire you.

That should be easy to follow , talk about widespread illiteracy.
vamsi_krishna
Oct 15, 2010 at 11:30 AM
use Dosbox. It is the only way to run 8bit and 16bit programs like Turbo C in Windows 7

Download DOSBox DOS Emulator from SourceForge.net

Follow the above link and download the file. Follow the instructions bundled.
Apple Juice
Oct 15, 2010 at 11:41 PM
Re: Turbo C in Windows 7

turbo c does not work in win 7 'coz no ntvm in win 7. :mad: install dosbox and in it install turbo c
elviento
elviento #263
Oct 21, 2010 at 2:58 PM
windows 7 x64 dosbox-turbo c problem

i managed to run turbo c in windows 7 x64
but my problem is that i cannot compile the program i write
it shows error
i've set the directories to the correct path but still it is not working
please help
*img217.imageshack.us/img217/4186/problemm.png
Liverpool_fan
Oct 21, 2010 at 6:11 PM
Re: windows 7 x64 dosbox-turbo c problem

^ You've given far less information. First where did you mount the dosbox's C:? Secondly where is your TC installed?
I suggest you to perform the TC installation inside dosbox, make sure, you create a self contained folder pointed by the virtual C: in DOSBOX.

As a side note I suggest to stay clear of the Turbo C compiler.
Refer to this thread: *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html
elviento
elviento #265
Oct 21, 2010 at 8:47 PM
Re: windows 7 x64 dosbox-turbo c problem

^ You've given far less information. First where did you mount the dosbox's C:? Secondly where is your TC installed?
I suggest you to perform the TC installation inside dosbox, make sure, you create a self contained folder pointed by the virtual C: in DOSBOX.

tc installation inside dosbox means??
and i installed the tc in h drive
then mouted it into

here is the complete thing..
*img135.imageshack.us/img135/2302/onet.png
*img842.imageshack.us/img842/2116/twox.png
*img529.imageshack.us/img529/7228/therr.png
and i'll check out the tutorial:smile:
elviento
elviento #266
Oct 21, 2010 at 9:32 PM
Re: windows 7 x64 dosbox-turbo c problem

sry for making double post...the edit button's not responding

the thing is that i don't know which one to download from
the site sound forge
i open minigw link and then there are so many links....
please give me the direct link to the software i need to download
thank you
S
sakumar79 #267
Oct 21, 2010 at 9:50 PM
Re: windows 7 x64 dosbox-turbo c problem

You have mounted the turbo c directory in U: within dosbox... So, when you are running turbo c, it should have reference to the U: drive and not the h: drive... If you correct it, it should work...

But again, as mentioned by Liverpool_fan, avoid turbo c as it is not standard...

Arun
elviento
elviento #268
Oct 21, 2010 at 10:09 PM
Re: windows 7 x64 dosbox-turbo c problem

got it....
i'll check

edit:
naaa.....still of no use

can anyone tell me what does this means???

"first of all download the executable and execute your downloaded executable in order to facilitate the installation of MinGW"

where's the executable i found none

source *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html
nbaztec
nbaztec #269
Oct 21, 2010 at 11:40 PM
Re: windows 7 x64 dosbox-turbo c problem

Well I made this for one of my friends having this issue. Maybe it will help you too. Helped 2 other people in diff. forums.
Download Here
Neuron
Neuron #270
Oct 22, 2010 at 12:29 AM
Re: windows 7 x64 dosbox-turbo c problem

Do these simple steps
1.Since you have installed turbo c in h:,type mount h: h:\
2.z:\>h:
3.h:\>turboc\TC\tc.exe
Liverpool_fan
Oct 22, 2010 at 1:37 AM
Re: windows 7 x64 dosbox-turbo c problem

got it....
i'll check

edit:
naaa.....still of no use

can anyone tell me what does this means???

"first of all download the executable and execute your downloaded executable in order to facilitate the installation of MinGW"

where's the executable i found none

source *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html
There's a link in that tutorial.
Anyway, download it from here:
*sourceforge.net/projects/mingw/fil...20100909/mingw-get-inst-20100909.exe/download
Get that automated installer
elviento
elviento #272
Oct 22, 2010 at 11:10 AM
Re: windows 7 x64 dosbox-turbo c problem

ok got it...i'll check it

i have a zip file called
mingw-w64-v1.0-snapshot-20101003.tar
what's that??

mmm.and again..what's that??
*img268.imageshack.us/img268/2020/downldfail.png

and... :p
haha...how to start after installing??
I open some apps then only a black window appears for a split second then it closes...
please help


and i tried dosbox runner suggested by nbaztec
but still wron directory msg pops up

think its better to leave turbo c
i'll go with minigw but someone tell me how to get it started?? :O
Liverpool_fan
Oct 22, 2010 at 6:58 PM
You may try Codeblocks which basically offers an integrated IDE with MinGW.
Code::Blocks
Download it here - *prdownload.berlios.de/codeblocks/codeblocks-10.05mingw-setup.exe

haha...how to start after installing??
I open some apps then only a black window appears for a split second then it closes...
please help
Which apps are you opening? Did you set the path for minGW?
elviento
elviento #274
Oct 22, 2010 at 7:52 PM
Re: windows 7 x64 dosbox-turbo c problem

You may try Codeblocks which basically offers an integrated IDE with MinGW.
Code::Blocks
Download it here - BerliOS Download - The Open Source Mediator


Which apps are you opening? Did you set the path for minGW?

i opened minigw.exe inside the bin folder i suppose...
(its in my laptop i'm using a desktop now)

one thing didn't get downloaded...wonder what

and no i didn't set the path.....i've seen the steps in the tutorial
but tell me why do we do that..i didn't understand it...


codeblocks...
the berilOS server is down...it shows "too many clients"
Liverpool_fan
Oct 22, 2010 at 8:45 PM
Re: windows 7 x64 dosbox-turbo c problem

i opened minigw.exe inside the bin folder i suppose...
(its in my laptop i'm using a desktop now)

one thing didn't get downloaded...wonder what

and no i didn't set the path.....i've seen the steps in the tutorial
but tell me why do we do that..i didn't understand it...


codeblocks...
the berilOS server is down...it shows "too many clients"
You don't double click the mingw.exe file. It's a text based application.
You first open the Command Prompt and then type the command, gcc or g++.
Basically you set the path because you need to run the gcc, g++ programs without specifying the full path.
I see you are not very experienced with command line. I guess Codeblocks would be perfect for you.
I can download Codeblocks BTW, try it again.
elviento
elviento #276
Oct 23, 2010 at 11:34 PM
Re: windows 7 x64 dosbox-turbo c problem

yup i'm weak in command line...
ok i'll try code blocks..
thank you
ajooba215
ajooba215 #277
Dec 29, 2010 at 8:17 PM
turbo c++ stopped working..

My turbo C++ have stopped working, God knows for what resaon...i havent used it for smtime...but i dnt wanto install OS again..is there any way to troubleshoot? i tried installing it again and in the other partition other than C: but dint work...the black DOS screen appears for couple of second after double clicking it and then it comes to normal..it ends automatically...i tried running it in safe mode too but no good....any help?
blackhole
blackhole #278
Dec 29, 2010 at 10:24 PM
Re: turbo c++ stopped working..

try us DOSBOX
A
abhijangda #279
Dec 29, 2010 at 11:17 PM
Re: turbo c++ stopped working..

why are u using Turbo C++.
Use Dev C++ or MS VC++ instead.
Ecko
Ecko #281
Dec 30, 2010 at 2:58 PM
Re: turbo c++ stopped working..

Run TurboC.exe from ur TC directory
Keep Pressing 'Y' When asked for an overwrite ;)
nims11
nims11 #282
Jan 3, 2011 at 8:05 AM
Re: turbo c++ stopped working..

Turbo sucks when we got compilers like dev and VC. i wonder why they still use it at schools(atleast my school)
arpanmukherjee1
Jan 3, 2011 at 10:48 AM
Re: turbo c++ stopped working..

Turbo sucks when we got compilers like dev and VC. i wonder why they still use it at schools(atleast my school)

not only yours but majory schools+colleges.

i tried to explain my computer graphics "professor" about standards and compatibility.

what do i get ?? -ve 5 for my practicals and out of 20 only me and my friend were the only two with working programs...
ajooba215
ajooba215 #284
Jan 4, 2011 at 8:25 PM
Re: turbo c++ stopped working..

but guys i tried using dev c++ but it shows error in library functions like graphics.h ....how can i fix that?
skeletor
skeletor #285
Jan 4, 2011 at 8:45 PM
Re: turbo c++ stopped working..

but guys i tried using dev c++ but it shows error in library functions like graphics.h ....how can i fix that?
Explained here: Dev-C++ Tutorial for CSC 161 Students

Turbo sucks when we got compilers like dev and VC. i wonder why they still use it at schools(atleast my school)
because Indians are idiots.
S
sid_gupta #286
Jan 4, 2011 at 11:03 PM
turbo c++ issues...

in windows 7 , turbo c++ window doesn't go full screen so i have to zoom in evry time.
any solution for this??
A
abhijangda #287
Jan 5, 2011 at 7:39 PM
Re: turbo c++ stopped working..

Actually i think the main problem is that indian writers prefers Turbo C like Yashwant Kanetkar in his book Let Us C
arpanmukherjee1
Jan 5, 2011 at 11:04 PM
Re: turbo c++ issues...

stop using the **#$@#@* turbo c++ ide

its been discussed millions of times on this forum.

use VC++ or devCpp
skeletor
skeletor #290
Jan 6, 2011 at 12:28 AM
Re: turbo c++ issues...

in windows 7 , turbo c++ window doesn't go full screen so i have to zoom in evry time.
any solution for this??
Stop using Turbo C++.
somulesnar
somulesnar #292
Jan 20, 2011 at 9:32 PM
Turbo C/C++ and other junk compilers discussions here

guys as we all know that we have been using the turbo c software and been writing c programs in a blue type screen since years. But the turbo c compiler is not working on the latest os that is windows 7.

plz guys suggest a sufficient and strong reason to support this.
if not suggest me another compiler..........
pulkitpopli2004
Jan 20, 2011 at 10:54 PM
Re: turbo c not working on windows 7

download dosbox version 0.7 or latest..
search on google... u will get to knw..
ajooba215
ajooba215 #295
Jan 23, 2011 at 3:15 PM
Re: turbo c not working on windows 7

get dosbox n run through it...
here is the link...

How to install Turbo C++ on Windows 7 64bit | Best Software 4 Download blog
A
Jan 23, 2011 at 11:32 PM
Re: turbo c not working on windows 7

try dev-c++
here is the link Bloodshed Software - Dev-C++
nims11
nims11 #297
Jan 24, 2011 at 8:52 PM
Re: turbo c not working on windows 7

i use dev-c++ in windows and g++ in ubuntu
sanoob.tv
sanoob.tv #298
Jan 30, 2011 at 9:08 PM
Re: turbo c not working on windows 7

dos box is the stuff you looking for,
download dos box and install it
open dos box
type
mount c c:\
c:
cd turboc
cd bin
tc

there you go,im assuming you have your turbo c installed in 'c' drive;
hope this helps
bijay_ps
bijay_ps #299
Mar 11, 2011 at 10:22 PM
Re: turbo c not working on windows 7

Hey Sanoob I am using windows 7 and i followed your method for dosbox,but when I compiled the program it showed the error message that "unable to locate STDIO.H and CONIO.H".
Any suggestions??
sanoob.tv
sanoob.tv #300
Mar 12, 2011 at 9:01 PM
Re: turbo c not working on windows 7

change the directory,
that is when u are in ur c/c++ editot(tc),go to options->then directories
it should look like this

*picasaweb.google.com/lh/photo/zYX49z9Mn4SN325ZLRfoZQ?feat=directlink

the image shows the directory setting in my pc.
i have installed turboc in my c drive.
and tc.exe is located in turboc/bin/tc.exe
damngoodman999
Mar 12, 2011 at 9:15 PM
Re: turbo c not working on windows 7

PM me your mail ID ! i ll send u .
rajsujayks
rajsujayks #302
Mar 13, 2011 at 5:15 PM
Re: turbo c not working on windows 7

guys as we all know that we have been using the turbo c software and been writing c programs in a blue type screen since years. But the turbo c compiler is not working on the latest os that is windows 7.

plz guys suggest a sufficient and strong reason to support this.
if not suggest me another compiler..........

Turbo C won't work in Windows 7 64-bit [as it isn't compatible with 16-bit programs] but would work in 32-bit...

As for an alternative C compiler...I'm a BE CSE student and I'm using Code::Blocks with the mingw gcc compiler... It's basically the same as Turbo C except some statements...It follows the GCC syntax (the proper ANSI C syntax) and if you can go through it, it's very good... :)
damngoodman999
Mar 13, 2011 at 6:37 PM
Re: turbo c not working on windows 7

^^ I ran turbo C in WIN 7 ! i have the whole to make it run without hassle .
rajsujayks
rajsujayks #304
Mar 14, 2011 at 7:28 PM
Re: turbo c not working on windows 7

^^ I ran turbo C in WIN 7 ! i have the whole to make it run without hassle .

Turbo C will run in Windows 7 32-bit perfectly...But not in Windows 7 64-bit unless you use an emulator like DOSBOX!
damngoodman999
Mar 14, 2011 at 7:33 PM
Re: turbo c not working on windows 7

Without using DOSCOX we made another step u want pm ur mail ID
TSPatange_1309
Apr 10, 2011 at 1:27 PM
how to open .txt file in turbo c++

Hey Hello Guyzz...:sad:I hav one programming query...!:sad: I am using turbo C++ in Win. Xp...the directory of TC is C:\Program Files\TC...I want to execute one program in TC...but its too big..! Thats y i copy-paste that program in notepad file as .txt...in BIN directory (C:\Program Files\TC\BIN)...Now i want to open that txt file in C...so first i open TC > File > Open....The name of my txt file is addons.txt...so i wrote C:\Program Files\TC\BIN\addons.txt in textbox...but after hitting enter just blank blue (default) screen is appearing again and again...its not opening in C...how to open it??? Plzz help me...!
Ryte now i am :arrow::arrow::arrow::shock:
krishnandu.sarkar
Apr 10, 2011 at 2:12 PM
Re: how to open .txt file in turbo c++

So basically that .txt file contains C program right??

Just name that file as xxx.cpp(For C++) / xxx.c(For C) instead of xxx.txt
Vyom
Vyom #308
Apr 10, 2011 at 3:55 PM
Re: how to open .txt file in turbo c++

C+ would have open the file, if you had input right filename, with right path.
So, when you click File -> Open, you should put *.txt in open dialog text box, this will allow you to select any .txt file inside the folders.

But, even if the file open, you can't compile it, since it would be a text file. So you would have to save as, it as a .cpp file.

So, in conclusion, you should have not saved the file as .txt in the first place. You can save it as a .cpp file in notepad itself. But do that selecting, "All files", under "Save as Type".
nims11
nims11 #309
Apr 10, 2011 at 9:12 PM
Re: how to open .txt file in turbo c++

dont use turbo c++. :D just kidding. do as krishnandu said!
S
sagarb #310
Apr 11, 2011 at 8:27 PM
Turbo C problem

Hi Friends,

I'm a student of Information Technology(I.T.) I own a laptop. Dell Inspirion N5010. Its configuration is as follows:-
4GB Ram
500GB Hard Disk
Intel Core i5 M460 @ 2.53GHz (turbo boost upto 2.8GHz)
Windows 7 Home Premium 64 bit
1GB Graphics Card.

My problem is that I can't run Turbo C and Turbo C++ on my system. I use Oracle Virtual Box and then run Turbo C & C++ in Windows XP Professional.

When I run a program of Bresenham's Algorithm, it doesn't give me any error when I press Ctrl+F9 and Alt+F9. But, when I try to run the program from the Run Option. I t gives me error.

There's no error in the coding of the program. I ran it successfully in my college's PC which have Windows XP as an OS.

Please help me out of this as my exams are approaching and I'm not able to practice despite of having my own system.

Sagar :-(
Neuron
Neuron #311
Apr 11, 2011 at 8:32 PM
Re: Turbo C problem

Could be a problem with the virtual environment.Use some other compilers like Microsoft Visual C++
Vyom
Vyom #312
Apr 11, 2011 at 9:31 PM
Re: Turbo C/C++ and other junk compilers discussions here

^ He is doing Graphics Programming and sadly he is stuck.

@Sagarb, First of all you need to run the TC IDE FULL SCREEN.

Make sure you enable the graphics libraries.


haha! I liked the name of this thread! "..other JUNK compilers" :-D

BTW, Ontopic:
@sagarb: You should provide the appropriate error messages and/or screen-shots, so that we can debug your error.
A
Apr 14, 2011 at 8:03 PM
Re: Turbo C/C++ and other junk compilers discussions here

hey all,
m learnin c++...i wantd to ask wat is the role og "getch()" in a program.....
i mean most of the programs mentioned in buks nd even on websites don't have a "getch" wriiten before closing main()....but i hv seen dat to get d desired result....i always have to add dis......

why is dis so?? nd is it necessary????



Hey friend Getch(); is used for a program which is modified like that it doesn`t returnany value.
it`s declaration is like :
void main()
here void is the return type .It shows that the current program doesn`t return any value.
i will show you a simple program compiled with Turbo c++:

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"HELLO";
getch();
}

if now you have any question __ please ask me!!!!!!!!!
shiwa436
shiwa436 #314
May 25, 2011 at 9:44 AM
Re: Post your C/C++ Programs Here

Do the following program prints the output 'hello'

void main()
{
if(printf("hello"))
}
Vyom
Vyom #315
May 25, 2011 at 10:07 AM
Re: Post your C/C++ Programs Here

Do the following program prints the output 'hello'

void main()
{
if(printf("hello"))
}

No, but the following would.


void main()
{
if(printf("hello"));
}
somulesnar
somulesnar #316
Jun 15, 2011 at 7:29 PM
Turbo c not working on windows 7

HII fellas

My turbo c is not working on full screen in windows 7 64 bit?
however it is working properly in small size window
plz help me to sort out this problem
if i press alt+enter it produce full screen but working of c stops it hangs up
and nothing works at that time

I want u guys to help me out find a better compiler for windows 7....
krishnandu.sarkar
Jun 15, 2011 at 7:33 PM
Re: Turbo c not working on windows 7

Read this guide : *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html

I really don't recommend using Turbo C. Why??? Read that guide I posted above.

And if you really don't have any option, use Doxbox : DOSBox, an x86 emulator with DOS
vamsi360
vamsi360 #318
Jun 15, 2011 at 8:15 PM
Re: Turbo c not working on windows 7

Use GCC and Geany.
Tejas.Gupta
Jun 15, 2011 at 10:15 PM
Re: Turbo c not working on windows 7

I too have the same problem but i dont see any solution to it.. :-/
And i suppose u need Turbo C because it is used in your CS classes, if i'am right :D
Same scenario is with me mate
krishnandu.sarkar
Jun 15, 2011 at 10:38 PM
Re: Turbo c not working on windows 7

^^In that case why don't you guys try Dosbox??
nbaztec
nbaztec #321
Jun 16, 2011 at 12:09 AM
Re: Turbo C/C++ and other junk compilers discussions here

I wish the Indian educational institutes can stop sucking on the tit of "I-only-know-this" mentality.

Apart from the conventional "sane" alternatives:
- MingW/GCC
- Code::Blocks (nice)
- Dev C++
- Microsoft Visual C++ Express (Heck, even M$ is doing their bit for the society).

There are other things:
- Emulate 16-bit working environment using DosBOX
- Emulate Virtual Machine. Some freewares are available. (My pref). VirtualBox. VMPlayer, etc.

If you're hell bent upon using the sundial to know the time and/or helpless 'coz Teh Old Folks think you're too small to outsmart them, here are my 2 cents:

- Full Screen for TC
- If you're too lazy to even bother with DosBox, here's a one-stop-single-click app. Just give path to TC and click. (Set directories within TC as: "INCLUDE" & "LIB", no paths)

P.S. Someone mentioned Yashwant Kanetkar, it's a sh!tty book with no regard to ANSI standards. It's a sad sad thing universities actually recommend this piece of crap.
tuxybuzz
tuxybuzz #322
Jun 23, 2011 at 11:30 PM
Re: Turbo C/C++ and other junk compilers discussions here

I really hate it when Turbo is referred to as C++..lol.
Most students don't even know that Turbo is not the goddamn language. Thankfully my lab has a linux box with gcc. :D
A
Oct 11, 2011 at 5:02 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

i installed DOSBOX 0.74 and turbo c++ in the directory c:\TC
But the BIN,INCLUDE and LIB folders are in a TC folder inside c:\TC
so when i launched tc++ with DOSBOX it showed invalid directory.So i changed the directory to C:\TC\TC\INCLUDE and C:\TC\TC\LIB.But still when i compile it shows iostream.h not found and so on...
thetechfreak
Oct 11, 2011 at 5:18 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

I think you should keep that directory empty. Even I got this error at my school sometimes.
nims11
nims11 #325
Oct 11, 2011 at 6:27 PM
Re: Turbo C/C++ and other junk compilers discussions here

after opening turboC++, goto options->directories and enter the path to the different directories there.
nbaztec
nbaztec #326
Oct 11, 2011 at 7:11 PM
Re: Turbo C/C++ and other junk compilers discussions here

Try the one-click app, mentioned in my post.
S
Oct 21, 2011 at 3:47 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

:?:
Hi guys , i m a beginner in c++ , i was trying to create a simple program that prints any random line for infinity times without interruption .. but it has to abort if the user wants ,say ( he can press any key to abort).

I tried the program like this

for(;;)
{
cout<<"hello";
cin>>ch;
if(ch=='y')break;
}




i encounter a problem that the program was stopping to take an i/p every time it get into the loop.... that is undesireable .....
plz help me out to solve this problem....

I would expect that i would get solution very soon
Vyom
Vyom #328
Oct 21, 2011 at 8:39 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

^ First of all, welcome to TDF. :-D

Well, you can use kbhit() function to interrupt an infinite loop.
But since the mentioned function use conio.h, I must give you a Non Portable Code warning.

It goes like this,

WARNING: NON-PORTABLE CODE
Code:
    while(1)
    {
        if (kbhit())
                break;
        cout << "\nHello.";
    }
A
aurora #329
Dec 17, 2011 at 12:06 AM
c++ graphics help

hello guys can any one help me with this problem i am having implemnting graphics in borland c++ version 5.02?(it's outdated but that's what cbse in it's unparalleld wisdom allows us to use). my problem is :- after carefully setting all the necessary prerequisites and including graphics.h(BGI graphics, DOS standard)when i try to compile the prog. it gives the error "not enough parameters to call initgraph with" whenever the first parameter in initgraph() is set to autodetect.when i try to do it by setting all parameters by hand, all i get is a flashing screen after which the program terminates. PLEASE HELP.
nims11
nims11 #330
Dec 17, 2011 at 9:46 AM
Re: c++ graphics help

try this
Code:
int gd=DETECT, gm;

initgraph(&gd, &gm, "c:\\turboc3\\bgi " );
change the third argument according to your compiler path
A
aurora #331
Dec 17, 2011 at 1:50 PM
Re: c++ graphics help

hello nims11 i tried what you suggested. the same problem persists, with the exception that the flashing console now shows this :-bgi error graphics not initialized use initgraph. wh:neutral:at do i do?
thetechfreak
Feb 10, 2012 at 2:53 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

guys need help with a c++ program

I need to add a statement "DO u want to continue, Y or N" after each page is completed. its a school project

tHIS IS the file link

Just a dummy file for project. No real functionality. need to submit tommorow.
Neuron
Neuron #333
Feb 10, 2012 at 3:02 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Add a boolean variable.Put all those choice selection statements in a while loop which runs as long as the bool flag is set.Reset the bool variable when the user answers no.
thetechfreak
Feb 10, 2012 at 3:14 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Book isnt helping. Program isnt helping. Pls upload or copy paste the complete code. will be thankfull :)
dashing.sujay
Feb 10, 2012 at 3:51 PM
Re: Turbo C/C++ and other junk compilers discussions here

^Why not use exit() with message ?
nims11
nims11 #336
Feb 10, 2012 at 4:04 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

guys need help with a c++ program

I need to add a statement "DO u want to continue, Y or N" after each page is completed. its a school project

tHIS IS the file link

Just a dummy file for project. No real functionality. need to submit tommorow.

Didnt get you problem.
Code:
do{
//.......
ch=getchar();
}while(ch=='y');
Vyom
Vyom #337
Feb 10, 2012 at 9:12 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

guys need help with a c++ program

I need to add a statement "DO u want to continue, Y or N" after each page is completed. its a school project

tHIS IS the file link

Just a dummy file for project. No real functionality. need to submit tommorow.

I have added a loop to repeat the content of main function. And put an extra option in the menu to Exit.
This is not asking Y/N since, now the user can exit when he wants to if he enters 0.

I hope this solves your problem.

PS: This code is Non-ANSI Compliant! Using which equates to 100 years of time in TDF Jail! You have been warned!

File: KARAN.CPP
thetechfreak
Feb 10, 2012 at 9:29 PM
Re: Turbo C/C++ and other junk compilers discussions here

@Vineet369 Thanks x10000000 :D
Absolutely amazing. Thanks a lot!!
dashing.sujay
Feb 10, 2012 at 9:50 PM
Re: Turbo C/C++ and other junk compilers discussions here

^Why the code is giving error? :confused:
nims11
nims11 #340
Feb 10, 2012 at 10:44 PM
Re: Turbo C/C++ and other junk compilers discussions here

coz it is for our great Blue screened compiler.
dashing.sujay
Feb 10, 2012 at 11:07 PM
Re: Turbo C/C++ and other junk compilers discussions here

^I'm using Dev C++
nims11
nims11 #342
Feb 10, 2012 at 11:30 PM
Re: Turbo C/C++ and other junk compilers discussions here

^^that's why, the code is non-ANSI, which doesn't guarantee it will run in a standard compiler (which Dev-C++ uses).
soumo27
soumo27 #343
Feb 11, 2012 at 10:01 AM
Re: Turbo C/C++ and other junk compilers discussions here

Well how is "Cfree" as a C compiler? (I m new to C; but well acquainted with JAVA).

MOD EDIT: This is not a general C/C++ thread. Read and ask if needed in the sticky thread.
U
Feb 11, 2012 at 4:08 PM
Re: Turbo C/C++ and other junk compilers discussions here

Well how is "Cfree" as a C compiler? (I m new to C; but well acquainted with JAVA).
CFree is not a compiler its an IDE
dashing.sujay
Feb 11, 2012 at 7:50 PM
Re: Turbo C/C++ and other junk compilers discussions here

^^that's why, the code is non-ANSI, which doesn't guarantee it will run in a standard compiler (which Dev-C++ uses).

Can you explain me what do you exactly mean by non-ANSI standards? Using outdated programming styles?
Vyom
Vyom #346
Feb 11, 2012 at 8:18 PM
Re: Turbo C/C++ and other junk compilers discussions here

Can you explain me what do you exactly mean by non-ANSI standards? Using outdated programming styles?

You may want to read this post by Who, and subsequent posts, if you like.
*www.thinkdigit.com/forum/programmi...de-post-basic-questions-here.html#post1288952
mohityadavx
Feb 23, 2012 at 11:51 PM
C++ Exponential output (Merged with Turbo C++ thread)

Here's a little code i have written but the problem is it gives output in exponential form whereas i want the output in numeric form plz suggest anyway to fix it

Code:
#include<iostream.h>
#include<conio.h>
void main()
{
ulong int first, second, url;
int third, fourth;
clrscr();
cout<<"Please enter the first part \n";
cin>>first;


cout<<"Please enter the second part \n";
cin>>second;


cout<<"Please enter the third part \n";
cin>>third;


cout<<"Please enter the fourth part \n";
cin>>fourth;

cout<<"/n";

url = (16777216*first) + (65536*second) + (third*256) + fourth;

cout<<url;
getch();
}
G
gopi_vbboy #348
Feb 23, 2012 at 11:59 PM
Re: C++ Exponential output

format n convert to string n output

or read this


faculty.cs.niu.edu/~mcmahon/CS241/c241man/node83.html
G
gopi_vbboy #350
Feb 24, 2012 at 12:05 AM
Re: C++ Exponential output

read this
Output Formatting
mohityadavx
Feb 24, 2012 at 12:35 AM
Re: C++ Exponential output

Thanks!
saswat23
saswat23 #352
Mar 18, 2012 at 11:40 AM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Want a C compiler for windows 7.
Can i get some download links (most probably looking for Turbo C).
dashing.sujay
Mar 18, 2012 at 12:50 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Don't use turboC. Its outdated and non-standard. Instead use at least Dev c++, but better use MS vc++ or gcc.
saswat23
saswat23 #354
Mar 18, 2012 at 4:41 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Can you plz give me there links. I couldn't find any of their dwnld links after googling.
Actually i wanted TurboC Bcoz its used in our college and i would be me more comfortable with it. But if others are better then i will surely try them.
dashing.sujay
Mar 18, 2012 at 4:43 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Dev C++

Visual Studio Express 2010 (VC++)
A
abhijangda #356
Mar 18, 2012 at 9:56 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

don't use Dev C++ instead use CodeBlocks, if you want to use mingw.
dashing.sujay
Mar 18, 2012 at 10:19 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Though devc++ is not updated since long its still good enough.
saswat23
saswat23 #358
Mar 18, 2012 at 11:13 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

k, will try it.
BTW which is the simplest C compiler.

But these are C++ compilers. Aint they different from C compilers?? I am looking for C compilers. And AFAIK C++ is different from C.
Am I wrong. If so plz do correct me. I am new to prog. And am totally unaware of all these.
dashing.sujay
Mar 18, 2012 at 11:20 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Dev C++ offers both, can't say about others.
krishnandu.sarkar
Mar 18, 2012 at 11:21 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

Check GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) and GCC - Wikipedia, the free encyclopedia

In simple words C is subset of C++.

You can compile C programs with C++ compiler.

But don't worry, you are not using C++ compiler.

To know more about MingW check MinGW | Minimalist GNU for Windows and MinGW - Wikipedia, the free encyclopedia

Check *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html for installing GCC
S
sarthak #361
Mar 19, 2012 at 10:29 AM
Re: Turbo C/C++ and other junk compilers discussions and queries here

k, will try it.
BTW which is the simplest C compiler.

But these are C++ compilers. Aint they different from C compilers?? I am looking for C compilers. And AFAIK C++ is different from C.
Am I wrong. If so plz do correct me. I am new to prog. And am totally unaware of all these.

There are two versions of C - C89 and C99. If you are new to programming you must be doing C89 in your college. C++ includes C89 but not C99. So you can compile C89 programs in those compilers mentioned above by simply saving them with extension ".c" instead of ".cpp". You need a C compiler only if you are going to do C99.
pratik385
pratik385 #362
Mar 22, 2012 at 12:29 PM
Re: Turbo C/C++ and other junk compilers discussions and queries here

MOD EDIT: Use this thread for junk compilers, use *www.thinkdigit.com/forum/programming/132924-c-c-beginners-guide-post-basic-questions-here.html for general C++ queries which doesn't involve the junk stuff. Likewise don't ask junk queries outside this thread. This post has been moved to the thread above - here.
A
Mar 24, 2012 at 10:49 AM
Re: Java Queries Here..

Wat s the difference b/w IDE and normal turbo c+ +
Is it just GUI n CUI
nims11
nims11 #364
Mar 24, 2012 at 1:01 PM
Re: Java Queries Here..

Wat s the difference b/w IDE and normal turbo c+ +
Is it just GUI n CUI

IDE - integrated development environment, which apart from being able to communicate with the compiler has features like editor, debugger, project management, etc.

TURBO C++ is an IDE with its compiler.

i think you mean to say the difference between turbo c++ and modern IDEs.
A
Mar 28, 2012 at 12:42 PM
Turbo c++ program problem!

code to be in turbo c++
Ok The question is :
WAP to generate a magic square of all possible combination (lowest no is 1 and all other integers less than equal to largest no. input by user). Data input by user: size of matrix, largest no in the matrix.
Magic square: The matrix is a square i.e. no. of rows=no. of columns.All the no are unique and principal diagonal sum=row sum=column sum=secondary diagonal sum.
ex:-
6 1 8
7 5 3
2 9 4
here: 6+1+8=6+5+4=8+5+2=6+7+2=1+5+9 and so on.(Hope question is clear enough.)

P.S.: I need solution in three days please help!
D
dbhaumik #366
Mar 28, 2012 at 1:04 PM
Re: Turbo c++ program problem!

void CalculateOddMagicSquare()
{
n=5;
int matrix[5][5];

int nsqr = n * n;
int i=0, j=n/2; // start position

for (int k=1; k<=nsqr; ++k)
{
matrix[j] = k;

i--;
j++;

if (k%n == 0)
{
i += 2;
--j;
}
else
{
if (j==n)
j -= n;
else if (i<0)
i += n;
}
}
}
A
Mar 28, 2012 at 3:14 PM
Re: Turbo c++ program problem!

void CalculateOddMagicSquare()
{
n=5;
int matrix[5][5];

int nsqr = n * n;
int i=0, j=n/2; // start position

for (int k=1; k<=nsqr; ++k)
{
matrix[j] = k;

i--;
j++;

if (k%n == 0)
{
i += 2;
--j;
}
else
{
if (j==n)
j -= n;
else if (i<0)
i += n;
}
}
}

Thanks for it but can you make it complete program for output to look like matrix (by complete I mean from #include to getch of main and of course it should ask the size of matrix and largest element just to set limitations on output if its not too much to ask.)
nbaztec
nbaztec #368
Apr 9, 2012 at 4:06 PM
Why don't people do their own homework :/
dbhauvmik gave you a near complete program yet you won't do it yourself. I pity you. I seriously do.
A
May 30, 2012 at 1:16 PM
can't find the bug

Can u please help me out?
consider the following code.

#include<stdio.h>
#include<conio.h>
main()
{
int num,p=0,n=0,z=0;
char choice='y';
while(choice=='y'||choice=='Y')
{
printf("Enter a number\n");
scanf("%d",&num);
if(num>0)
p++;
else if(num<0)
n++;
else
z++;

printf("Do you want to enter another number\n");
scanf("%c",&choice);
}

printf("positive number=%d negative=%d zero=%d",p,n,z);
getch();
}

when i run this code, after pressing any number, program goes out of the loop.

if i remove scanf("%c",&choice) and run the program, and press any alphabet key, it results in an infinite loop saying "do you want to enter another number",(WHY ?)

how can i fix the bug?
A
May 30, 2012 at 1:30 PM
why am i getting an infinite loop?

//program to generate armstrong number less than 500
#include<stdio.h>
#include<conio.h>
main()
{
int num=1,i,a,b;
while(num<=500)
{
i=num;
a=num%10;
num=num/10;
b=num%10;
num=num/10;
if((a*a*a)+(b*b*b)+(num*num*num)==i)
printf("\n%d",i);

num++;
}
getch();
}
nims11
nims11 #371
May 30, 2012 at 1:50 PM
Re: can't find the bug

Can u please help me out?
consider the following code.

#include<stdio.h>
#include<conio.h>
main()
{
int num,p=0,n=0,z=0;
char choice='y';
while(choice=='y'||choice=='Y')
{
printf("Enter a number\n");
scanf("%d",&num);
if(num>0)
p++;
else if(num<0)
n++;
else
z++;

printf("Do you want to enter another number\n");
scanf("%c",&choice);
}

printf("positive number=%d negative=%d zero=%d",p,n,z);
getch();
}

when i run this code, after pressing any number, program goes out of the loop.

if i remove scanf("%c",&choice) and run the program, and press any alphabet key, it results in an infinite loop saying "do you want to enter another number",(WHY ?)

how can i fix the bug?

replace scanf("%d",&num); with scanf("%d\n",&num);
replace scanf("%c",&choice); with scanf("\n%c",&choice);
nims11
nims11 #372
May 30, 2012 at 1:54 PM
Re: why am i getting an infinite loop?

//program to generate armstrong number less than 500
#include<stdio.h>
#include<conio.h>
main()
{
int num=1,i,a,b;
while(num<=500)
{
i=num;
a=num%10;
num=num/10;
b=num%10;
num=num/10;
if((a*a*a)+(b*b*b)+(num*num*num)==i)
printf("\n%d",i);

num++;
}
getch();
}
the condition for the while loop to continue is num<=500. Inside the loop however, you are dividing the num by 10 and then incrementing it by 1. So you can imagine if the num will ever cross 500!
in your case, num is one. inside the while loop,
num=num/10
.
.
num=num/10
.
.
num++
so num always remains 1.

to solve this problem, take a separate variable, say num2 and assign the value of num to it in the beginning of the loop.
S
sakumar79 #373
May 30, 2012 at 1:56 PM
Re: why am i getting an infinite loop?

You are dividing num by 10 and then adding one to it in each loop. How will num increase?
num=num/10=1/10=0 (integer value), then num++ will make it num=1. It will forever be in loop since it will not change...

Arun

PS: A couple of minutes too late with my reply I see... Already answered.
Vyom
Vyom #374
May 30, 2012 at 2:16 PM
Re: can't find the bug

if i remove scanf("%c",&choice) and run the program, and press any alphabet key, it results in an infinite loop saying "do you want to enter another number",(WHY ?)

It's obvious that if you remove the scanf("%c",&choice); statement that you will stuck in an infinite loop, since the value of choice will always be y and condition will never be false.
And there's another way to take input to char. Try that. Keeping in mind the nature of the question, I hope LFC_fan won't mind the alternate statement that I am going to write.

@amrutansu garanaik : Replace that line with: choice = getch(); or choice = getche();
somulesnar
somulesnar #375
Jun 23, 2012 at 8:11 AM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Hey guys this is a simple question to find the gcd using euclidean algorithm...

Question: The process is based on the observation that, if r is the remainder when a
is divided by b, then the common divisors of a and b are the same as the
common divisors of b and r. Thus we can use the equation
gcd(a, b) = gcd(b, r)
to successively reduce the problem of computing a GCD to the problem of
computing the GCD of smaller and smaller pairs of integers. For example,
gcd(36,20) = gcd(20, 16) = gcd(16, 4) = gcd(4, 0) = 4
implies that the GCD of 36 and 20 is 4. It can be shown that for any two
starting numbers, this repeated reduction eventually produces a pair where the
second number is 0. Then the GCD is the other number in the pair.
Write a method called gcd that takes two integer parameters and that uses
Euclid's algorithm to compute and return the greatest common divisor of the
two numbers.



#include <stdio>

int euclid(int a,int b)
{
if(b==0)
return a;
else
return euclid(b,a%b);
}

int main()
{
int n1,n2;
cout<<"Enter two numbers to find its GCD:"<<endl;
cin>>n1>>n2;
cout<<"The GCD of n1 and n2 is"<<euclid(n1,n2)<<endl;
return 0;
}

This is a simple code that i hv written to solve this and hopefully it worked. But when i tried to put on a diffrent logic using recursion i am getting errors and the code fails to execute...
Here is the recursive code tht i have written. Need ur expertise suggestions on this as i am a novice to this simple yet strong object oriented programmig language c++...

#include<stdio.h>
class Euclid
{
static int gcd(int a, int b)
{
int r=a%b;
if(r==0)
{
return b;
}
else
{
int recurse=gcd(b,r);
return recurse;
}
}
void main()
{
int p;
int q;
cout<<"Enter the value of p"<<endl;
cin>>p;
cout<<"Enter the value of q"<<endl;
cin>>q;
cout<<gcd(p,q);
}
nims11
nims11 #376
Jun 23, 2012 at 9:14 AM
Re: C/C++ Beginner's Guide and Post Basic Questions here

^^why are you going through the trouble of defining the function in the class?
Code:
int gcd(int a,int b)
{
    if ( b == 0 )
    return a;
    else
    return gcd(b,a%b);
}
somulesnar
somulesnar #377
Jun 23, 2012 at 9:24 AM
@nims11

yes i did tht to make the use of class concept in the program....but did tht create any prob in the code??
nims11
nims11 #378
Jun 23, 2012 at 10:41 AM
@nims11

yes i did tht to make the use of class concept in the program....but did tht create any prob in the code??

yes, your class concept code is full of all kinds of problems.
Here, i corrected your code
Code:
#include<iostream>
using namespace std;
class Euclid
{
    public:
    static int gcd(int a, int b)
    {
        int r=a%b;
        if(r==0)
        {
            return b;
        }
        else
        {
            int recurse=gcd(b,r);
            return recurse;
        }
    }
};
int main()
{
    int p;
    int q;
    cout<<"Enter the value of p"<<endl;
    cin>>p;
    cout<<"Enter the value of q"<<endl;
    cin>>q;
    cout<<Euclid::gcd(p,q);
    return 0;
}
nbaztec
nbaztec #379
Jun 23, 2012 at 10:53 AM
Re: C/C++ Beginner's Guide and Post Basic Questions here

^^why are you going through the trouble of defining the function in the class?
Because he copied the code from here without correctly mapping it to C++.
somulesnar
somulesnar #380
Jun 23, 2012 at 6:15 PM
@nbaztec

I didnt copy it actually i just had gone through the code that my frnd vickybat had posted...he gave me a wider scope to the euclidean concept....And if a person wants to learn then he is free to learn frm all scopes tht he wants or he gets and thts called learning or gaining knowledge frm wat he see's and not copying....plz consider ur suggestion...i agree tht am a novice to this thread and as well as to the language so plz try to help me not to demoralize me frm posting in the thread. Its not an advice but a simple request......

@nims11

Thnx for ur correction it helped me a lot..
nbaztec
nbaztec #381
Jun 23, 2012 at 8:04 PM
@somulesnar,

Apologies if you got offended mate. I did not mean that. What I emphasized upon was you got the code from there and didn't map it correctly hence it was inside the class. If you correctly accredit the original source, people here can better inform you what you are doing wrong, and not just about the code, but the practices as well.
somulesnar
somulesnar #382
Jun 23, 2012 at 10:32 PM
^^ Its alright buddy. I ama a novice and i am very eager to expertise in this language. Hope that i ll get more help when i post some more codes in future.
Cheers.
somulesnar
somulesnar #383
Jun 24, 2012 at 12:56 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Here's is a simple bubble sort program.

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[5]={33,1,42,78,2};
int i,j,temp;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("The array after sorting is:\n ");
for(i=0;i<=4;i++)
printf("\n%d",arr);
getch();
}
nbaztec
nbaztec #384
Jun 24, 2012 at 12:59 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Here's is a simple bubble sort program.

#include<stdio.h>
#include<conio.h>
main()
{
int arr[5]={33,1,42,78,2};
int i,j,temp;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("The array after sorting is:\n ");
for(i=0;i<=4;i++)
printf("\n%d",arr);
getch();
}


The default return value for a function in C is int. You're not returning anything. Indent your code.
somulesnar
somulesnar #385
Jun 24, 2012 at 1:14 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

^^But in C if the coder doesnt specify the return type it means that it can return any type of data. Infact the compiler doesnt show any errors and the code executes prorperly.
nbaztec
nbaztec #386
Jun 24, 2012 at 1:19 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

No. That's incorrect.

Which compiler are you using?
somulesnar
somulesnar #387
Jun 24, 2012 at 1:23 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

oops sorry i was wrong. was thinking of something else. post has been deleted. And the code has been edited. thnx for the correction.
nbaztec
nbaztec #388
Jun 24, 2012 at 1:25 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

oops sorry i was wrong. was thinking of something else. post has been deleted. And the code has been edited. thnx for the correction.

Why'd you delete the post? :-?
somulesnar
somulesnar #389
Jun 24, 2012 at 1:53 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

^^ Bcoz i was arguing over my mistake. So i deleted it.
skeletor
skeletor #390
Jun 24, 2012 at 2:21 PM
Four things:

1) Indent your code.
2) Use [ code ] ***** [ /code ] instead of spoiler.
3) Use an ANSI compliant compiler. Otherwise you are not learning C/C++, but just wasting your time.
4) Post in the Beginner C/C++ thread only if you're writing ANSI compliant code. Not outdated stuff using an outdated compiler. (Turbo C/C++)
somulesnar
somulesnar #391
Jun 24, 2012 at 6:56 PM
@ico

would surely see to the four things stated by you in my upcoming codes. Thnx for the suggestiion.
somulesnar
somulesnar #392
Jun 24, 2012 at 9:51 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.
skeletor
skeletor #393
Jun 24, 2012 at 10:13 PM
Which book are you using to study? :)
nbaztec
nbaztec #394
Jun 24, 2012 at 10:52 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.

Again, trotting past the fact that you are writing non-standard code, you've failed to return value from main().
digit.sh
digit.sh #395
Jun 25, 2012 at 8:23 AM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.

For god's sake do not use those nonstandard functions like clrscr() and conio.h crap. If your compiler doen't let you compile without those things, get rid of the compiler. Code::blocks is free, why don't use that?
And follow a better book. "The C programming language(ANSI)" by Kernighan and Ritchie is the best. Also there are "C in a nutshell" by Peter Prinz. and there are good online tutorials for C. Maintain the STANDARD. Please!:|
skeletor
skeletor #396
Jun 25, 2012 at 10:03 AM
well, there was a reason why I said not to learn C as your first language in India. You're most likely to choose the wrong path. Indians have raped the beautiful language by sticking with Turbo C/C++ and writing useless books. eg, Sumita Arora, Yashavant Kanetkar etc. :(

The C Programming Language 8120305965: Book: Brian W. Kernighan (9788120305960) | Flipkart.com

Buy this. Very cheap and this is written by the creators of C.
krishnandu.sarkar
Jun 25, 2012 at 10:25 AM
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.
digit.sh
digit.sh #398
Jun 25, 2012 at 12:41 PM
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.

^^ You already know C. You shouldn't find K&R hard to grasp. K&R is a must for someone keen to learn C. Not only its authentic, its beautifully written too.

Anyway, I found the following:
1> C Tutorial - Learn C - Cprogramming.com
2> C Programming
3> C Tutorial
4> *phy.ntnu.edu.tw/~cchen/ctutor.pdf
5> ftp://ftp.math.uh.edu/pub/sanders/Math6378-sp12/Documents/C+F77/oxford-CTutorial.pdf

Among the above links, 1 and 2 are more basic than the rest. So they may qualify as "for beginners". No. 4 is good but it follows the GNU standard of C, which means its not platform neutral in some cases. No. 5 is absolutely platform neutral and the best IMO. It strictly follows the ANSI standard and points out differences from "K&R" standard where it matters. I liked 4 and 5 the most.:wink:
Happy learning:wink:
Liverpool_fan
Jun 25, 2012 at 12:42 PM
Head First C. :)
And yes, always report the cases of non-standard code floating around outside this thread. They always need to be thrown into this trash thread, designed for the losers to ask questions for their loser queries and for sympathetic posters to help them.
And oh not another book discussion please. The main C/C++ sticky is nothing except newbies asking for books without even going through the thread OP. Same answers being rehashed again, and again.
nims11
nims11 #400
Jun 25, 2012 at 1:26 PM
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.

Thinking in C++ is not for beginners. It is for people comfortable with C or basic C++.

Regarding standards, i don't feel they play any role in determining how much the programmer learns as switching standards is not a big deal although sticking to the current standard is the always better. A newbie won't be using stuffs like STL and dynamic casts anyway!
somulesnar
somulesnar #401
Jun 25, 2012 at 3:33 PM
well, there was a reason why I said not to learn C as your first language in India. You're most likely to choose the wrong path. Indians have raped the beautiful language by sticking with Turbo C/C++ and writing useless books. eg, Sumita Arora, Yashavant Kanetkar etc. :(

The C Programming Language 8120305965: Book: Brian W. Kernighan (9788120305960) | Flipkart.com

Buy this. Very cheap and this is written by the creators of C.

Agree with you man. I am tired of this turbo C compiler. Sorry guys for the inconvenience, would try to post better codes coping up the standard. And i am going to get code blocks for sure.

BTW i am using programming in C- By Byron S Gotfried (schaum's outlines).
A
Jul 5, 2012 at 12:37 PM
dosbox and c++

Hi,
I have a 64bit windows 7 Home Premium computer and I want to run turbo c++ 4.5 in it. Need help.

I tried running installation file through dosbox but it says the file must run under windows. I installed it on my pen drive and run tcw.exe but the result is same-"the file must be run under windows". Again direct installation on laptop gives compatibility error.

I need it to do dos programming through c. I couldn't understand DJGPP so couldn't install it.

Please help.
saswat23
saswat23 #403
Jul 5, 2012 at 1:14 PM
Re: dosbox and c++

This might help: Turbo C for Windows 7 64 Bit download with one click installer | Indian Exam Updates: IndiaExam
M
Mario #404
Jul 5, 2012 at 1:19 PM
Re: dosbox and c++

Hi,
I have a 64bit windows 7 Home Premium computer and I want to run turbo c++ 4.5 in it. Need help.

I tried running installation file through dosbox but it says the file must run under windows. I installed it on my pen drive and run tcw.exe but the result is same-"the file must be run under windows". Again direct installation on laptop gives compatibility error.

I need it to do dos programming through c. I couldn't understand DJGPP so couldn't install it.

Please help.

Trash that compiler NOW! That is, if you want to learn "C" and not "101 ways to how to not program in C!"
Anish
Anish #405
Jul 5, 2012 at 10:10 PM
Re: dosbox and c++

Install GNU C compiler
akii17kr
akii17kr #406
Jul 8, 2012 at 10:01 PM
pLz. help in solivng a C question...

*img195.imageshack.us/img195/5661/salary.jpg
actually i am stuck at one question
after running it it tells always SALARY=0.
i amnot able to find out error so help me in finding error.

question is in attached URL with questi0n and solution which is given in the book "let us c"

and i tried to do it in the way which my computer teacher taught me earlier

here's my coding:


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char g,pg,ug;
int yos,q,s=0;

printf("\n Enter the gender , year of service ,qualification:");
scanf(" %c %d %d ",&g,&yos,&q);

if(g=='m' && yos>=10 && q==pg)
s=15000;

else if((g=='m' && yos>=10 && q==ug)||(g=='m' && yos<10 && q==pg))
s=10000;

else if(g=='m' && yos<10 && q==ug)
s=7000;

else if(g=='f' && yos>=10 && q==pg)
s=12000;

else if(g=='f' && yos>=10 && q==ug)
s=9000;

else if(g=='f' && yos<10 && q==pg)
s=10000;

else if(g=='f' && yos<10 && q==ug)
s=6000;

printf("\n salary of employee=%d\n",s);
getch();
}




and btw i also tried da method given in book and still it does not tell the salaray....

here's book method :



#include<stdio.h>
int main()
{
char g;
int yos,qual,sal=0;

printf("Enter gender ,year of service and qualifications(0=g,1=pg):");
scanf("%c%d%d",&g,&yos,&qual);

if(g=='m' && yos>=10 && qual==1)
sal=15000;

else if((g=='m' && yos>=10 && qual==0)||(g=='m' && yos<10 && qual==1))
sal=10000;

else if(g=='m' && yos<10 && qual==0)
sal=7000;

else if(g=='f' && yos>=10 && qual==1)
sal=12000;

else if(g=='f' && yos>=10 && qual==0)
sal=9000;

else if(g=='f' && yos<10 && qual==1)
sal=10000;

else if(g=='f' && yos<10 && qual==0)
sal=6000;

printf("\n salary of employee=%d\n",sal);
return 0;



thx in advance
rijinpk1
rijinpk1 #407
Jul 8, 2012 at 11:03 PM
Re: pLz. help in solivng a C question...

printf("\n Enter the gender , year of service ,qualification:\n");
try that.
Put \n at the end of printf. This should solve. Try and reply
K
Jul 8, 2012 at 11:03 PM
Re: pLz. help in solivng a C question...

Best way to ask google
akii17kr
akii17kr #409
Jul 8, 2012 at 11:52 PM
Re: pLz. help in solivng a C question...

printf("\n Enter the gender , year of service ,qualification:\n");
try that.
Put \n at the end of printf. This should solve. Try and reply
it too duz'nt work bro
can u own try dis question in ur own way if u have time well its not necessary but if u can do den plz. post the code here
thx..

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char g,q[2];
int yos,s=0;
printf("\n Enter the gender , year of service ,qualification:");
scanf(" %c %d %s ",&g,&yos,q);
if(g=='m' && yos>=10 && q=="pg")
s=15000;
else if((g=='m' && yos>=10 && q=="ug")||(g=='m' && yos<10 && q=="pg"))
s=10000;
else if(g=='m' && yos<10 && q=="ug")
s=7000;
else if(g=='f' && yos>=10 && q== "pg")
s=12000;
else if(g=='f' && yos>=10 && q=="ug")
s=9000;
else if(g=='f' && yos<10 && q=="pg")
s=10000;
else if(g=='f' && yos<10 && q=="ug")
s=6000;
printf("\n salary of employee=%d\n",s);
getch();
}

well only difference with ur coding and my coding is dat u hv putted " and " in b/w the ug and pg

i've tried it too but it gives error of cannot convert char to char

does it work on ur pc or lappy ??
btw i am using turbo c++
rijinpk1
rijinpk1 #410
Jul 9, 2012 at 12:03 AM
Re: pLz. help in solivng a C question...

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char g,q;
int yos,s=0;
printf("\n Enter the gender , year of service ,qualification:");
scanf(" %c %d %c ",&g,&yos,&q);
if(g=='m' && yos>=10 && q=="pg")
s=15000;
else if((g=='m' && yos>=10 && q=="ug")||(g=='m' && yos<10 && q=="pg"))
s=10000;
else if(g=='m' && yos<10 && q=="ug")
s=7000;
else if(g=='f' && yos>=10 && q== "pg")
s=12000;
else if(g=='f' && yos>=10 && q=="ug")
s=9000;
else if(g=='f' && yos<10 && q=="pg")
s=10000;
else if(g=='f' && yos<10 && q=="ug")
s=6000;
printf("\n salary of employee=%d\n",s);
getch();
}

Sry for my deleted post. q refers either pg or ug . Dont store it as integer variable. Use char.
akii17kr
akii17kr #411
Jul 9, 2012 at 10:45 AM
Re: pLz. help in solivng a C question...

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char g,q;
int yos,s=0;
printf("\n Enter the gender , year of service ,qualification:");
scanf(" %c %d %c ",&g,&yos,&q);
if(g=='m' && yos>=10 && q=="pg")
s=15000;
else if((g=='m' && yos>=10 && q=="ug")||(g=='m' && yos<10 && q=="pg"))
s=10000;
else if(g=='m' && yos<10 && q=="ug")
s=7000;
else if(g=='f' && yos>=10 && q== "pg")
s=12000;
else if(g=='f' && yos>=10 && q=="ug")
s=9000;
else if(g=='f' && yos<10 && q=="pg")
s=10000;
else if(g=='f' && yos<10 && q=="ug")
s=6000;
printf("\n salary of employee=%d\n",s);
getch();
}

Sry for my deleted post. q refers either pg or ug . Dont store it as integer variable. Use char.

i've also tried dat bro...but still same orblm.. SALARY=0 . :p
M
Mario #412
Jul 10, 2012 at 7:21 PM
Re: pLz. help in solivng a C question...

i've also tried dat bro...but still same orblm.. SALARY=0 . :p

Isnt char q only going to store a single character? But you are comparing multiple characters in your condition statement.
raj_55555
raj_55555 #413
Jul 25, 2012 at 1:29 PM
Re: pLz. help in solivng a C question...

rijinpk1 said:
This little part of your code has disturbingly large number of issues.

1. q is a character, not a string. You can do q='p' or q='g'. But not both at once, simply because it doesn't have the space to keep both the characters at once.
Just printf() the value of q before comparing and you'll know what I am saying.

2. Even if q was a string(which it is not), and you could store "pg" into q; you coudn't possibly check for a match by using "==" operand. This only works for numbers, you need strcmp() function (declared in string.h) to compare strings.

3. In the previous line, i.e. the scanf, you're not validating whether it succeeded or not. You must always check the input functions for success, never assume anything.
R
Sep 18, 2012 at 1:17 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Kindly provide an explanation for this code snippet. I couldn't understand how the output was calculated.

int main()
{
int a=1;
a=(++a)+(++a);
printf("a value is %d",a);
return 0;
}

when run in Turbo C, this program produces 6 as output. How is it achieved.?
Anish
Anish #415
Sep 18, 2012 at 11:24 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Kindly provide an explanation for this code snippet. I couldn't understand how the output was calculated.

int main()
{
int a=1;
a=(++a)+(++a);
printf("a value is %d",a);
return 0;
}

when run in Turbo C, this program produces 6 as output. How is it achieved.?

How about this? the o/p is calculated by this method...
#include "stdio.h"
int main()
{
int a=1;
a=(++a);
printf("a value is %d",a);
a=(++a);
printf("a value is %d",a);
a=a+a;
printf("a value is %d",a);
return 0;
}

Like the above code,
the compiler first does the ++a and stores the result (2) in a.
Then it computes ++a again and stores back the result (3) in a (overwrites 2 in this case with 3)
now, adding both, will add 3+3 and gives you answer as 6.

EDIT: Use GCC
nims11
nims11 #416
Sep 19, 2012 at 12:36 AM
^^ What you said is just shooting in the dark. I believe the answer to the question asked by rakesh is undefined and is compiler dependent. see Sequence point - Wikipedia, the free encyclopedia
Anish
Anish #417
Sep 19, 2012 at 9:27 AM
^^ What you said is just shooting in the dark. I believe the answer to the question asked by rakesh is undefined and is compiler dependent. see Sequence point - Wikipedia, the free encyclopedia

Yes, its just my assumption of how the code works. But I get the same result even while using GCC.
PS: I just know to play with C and data structures. Not indepth of it. :(
R
Sep 19, 2012 at 1:02 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

#include "stdio.h"
int main()
{
int a=1;
a=(++a);
printf("a value is %d",a);
a=(++a);
printf("a value is %d",a);
a=a+a;
printf("a value is %d",a);
return 0;
}

Like the above code,
the compiler first does the ++a and stores the result (2) in a.
Then it computes ++a again and stores back the result (3) in a (overwrites 2 in this case with 3)
now, adding both, will add 3+3 and gives you answer as 6.

Thanks for the explanation. BTW I am using Turbo C as part of my college lab manual, not willingly. I practice using CodeBlocks back at home. [Anna Univ syllabus strictly mentions to prepare with Turbo C for labs]
quagmire
quagmire #419
Sep 22, 2013 at 1:58 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Guys need a little help in Code Blocks:

I am working on a linked list program in Data Structures: The aim is to create an ordered linked list.
The following code works perfectly fine in TurboC:
Code:
//Program to create an ardered linked list

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

struct node
{
    int info;
    struct node *link;
};

typedef struct node *NODE;

NODE getNode()
{
    NODE x;
    x=(NODE)malloc(sizeof(struct node));
    if(x==NULL)
    {
        printf("\nOVER FLOW");
        exit(0);
    }
    return x;
}

NODE insertOrder(NODE first, int item)
{
    NODE prev=NULL, cur=NULL, temp;
    temp= getNode();
    temp->info=item;
    temp->link=NULL;

    if(first==NULL)
    {
        return temp;
    }
    if(first->link==NULL)
    {
        if(item>first->info)
        {
            first->link=temp;
            return first;
        }

        if(item<=first->info)
        {
            temp->link=first;
            return temp;
        }
    }
    prev=NULL;
    cur=first;

    while((cur!=NULL)&&(item>temp->info))
    {
        prev=cur;
        cur=cur->link;
    }

    if(cur==NULL)
    {
        cur->link=temp;
        temp->link=NULL;
        return first;
    }
    prev->link=temp;
    temp->link=cur;
    return first;
}

void display(NODE first)
{
    NODE temp;
    temp=first;
    if (first == NULL)
    {
        printf("List is empty \n");
        getch();
        exit(0);
    }
    printf("\nThe contents of singly linked list are:\n");
    temp=first;

    while(temp!= NULL)
    {
        printf("\t%d",temp->info);
        temp=temp->link;
    }
}


void main()
{
    NODE first=NULL;
    int item, choice;
    for( ; ; )
    {
        printf(" \nEnter you choice:\n1. Insert();\n2. Display()\n3. Exit()\n\n");
        scanf("%d",&choice);

        switch(choice)
        {
            case 1: printf("\nEnter the item:\n");
                    scanf("%d",&item);
                    first = insertOrder(first,item);
                    break;

            case 2: display(first);
                    break;

            default: exit(0);
        }
    }
}


But in Codeblocks I get an output saying:
*www.thinkdigit.com/forum/attachment.php?attachmentid=12226&d=1379837682
codeblocks crash.JPG
(Most usually when I try to enter the third info/item)

I just read on stackoverflow that '0xc0000005' is some kind of invalid pointer error.. I dont see any such in my code. :|

Any mistakes I've made?

cplusplus forum
skeletor
skeletor #420
Sep 22, 2013 at 1:59 PM
Read the first post of this thread.

Code properly. Which book are you referring to? conio.h? void main()?

Don't read from it.
quagmire
quagmire #421
Sep 22, 2013 at 2:10 PM
^Actually thats the code I wrote.. I am referring to book by 'Forouzan & Gilberg' and another by 'Padma Reddy'
skeletor
skeletor #422
Sep 22, 2013 at 2:35 PM
Don't read Padma Reddy. It's only applicable for ancient compilers like Turbo C running on ancient operating systems like Windows 3.11.

conio.h, process.h are historic header files for DOS machines.
digit.sh
digit.sh #423
Sep 23, 2013 at 9:51 AM
Don't read Padma Reddy. It's only applicable for ancient compilers like Turbo C running on ancient operating systems like Windows 3.11.

conio.h, process.h are historic header files for DOS machines.

^You did not mention nonstandard -- the single biggest reason to avoid it.
©mß
©mß #424
Nov 3, 2013 at 3:45 PM
Okay, so I wrote a program in Turbo C++ and saved it. But I want a .exe file.
How do I get it?
harshilsharma63
Nov 3, 2013 at 3:55 PM
Okay, so I wrote a program in Turbo C++ and saved it. But I want a .exe file.
How do I get it?

Did you notice this very important word in the thread's title: "Turbo C/C++ and other junk compilers help, discussions and queries here".

I don't know how to get an exe in TC, but I surely know that you should upgrade from a >10 years old highly obsolete compiler to a modern compiler like GCC/G++ or Visual Studio.
©mß
©mß #426
Nov 3, 2013 at 4:02 PM
But what they are teaching me in school is Turbo C++ :/
N
Nue #427
Nov 3, 2013 at 5:24 PM
But what they are teaching me in school is Turbo C++ :/
Regardless, as already suggested, you should familiarize yourself with industry standard compilers such as Visual studio and GCC. It'll pay off later :)
tech0freak0
Dec 28, 2013 at 6:06 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Hey Guys,
Visual Studio is good for learning c..?
I couldn't understand use of void in c and cpp, is this still used in modern world?

What really wrong with Turbo C, I want to elaborate to my teacher...
aaruni
aaruni #429
Dec 28, 2013 at 6:13 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

C/C++ Thread .

As far as I understand, void is for functions which don't return a value. It is deprecated, and produces warnings when run in GCC .
flyingcow
flyingcow #430
Dec 28, 2013 at 6:25 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

is cin>> and cout<< a predefined function??
and is clrscr() needed??? bcoz isnt the screen already blank??
aaruni
aaruni #431
Dec 28, 2013 at 6:35 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

cin and cout are not functions, but input and output objects, defined in the istream / ostream / iostream header files.

clrscr() is defined in the header conio.h , and is a dos only implementation. It is required so that each time your program is run, it is run on a blank console screen, and nothing from the previous program runs, or if you use the console, then all your commands and the console responses are seen.
harshilsharma63
Dec 28, 2013 at 6:48 PM
Re: C/C++ Beginner's Guide and Post Basic Questions here

Hey Guys,
Visual Studio is good for learning c..?
I couldn't understand use of void in c and cpp, is this still used in modern world?

What really wrong with Turbo C, I want to elaborate to my teacher...

> I would strongly suggest not using VS for C. You'll have to use the 'VS developer command line tool' to compile C code as there is no choice for C project in VS. Additionally, VC's C compiler is based on C89 stranded, not even C99. I would suggest eclipse+mingw for C and even C++ for beginner.

> void means nothing. When used as function return type, it means nothing will be returned. When used in functions parameter list, it means nothing will be accepted. Additionally, you can create void pointers too which are called 'generic pointers'. These can point to objects of any type unlike common pointers which point to only one type of objects.

> Turbo C is light years behing the industry. It has not been updated to implement new C/C+ versions. It still provides functions which have been deprecated or declared unsafe for use. Google this for more technical details :)
D
db22 #433
Jan 2, 2014 at 12:45 PM
guys i need c and c++ compilers.. my email id is dpnkrborah@gmail.com...it would of great help if u send me the files or provide me with links to download the compilers from