Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16949

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
executing programs in Turbo C++ "run" window Posted by earlyriser1 on 15 Sept 2009 at 2:36 AM
hi,
here is the program:

/*file:avrage.c*/
#include<stdio.h>

/* calculate the average of three numbers */
void main()
{
int num1, num2, num3;
float avg;

printf("enter 3 integer numbers:");
scanf(" %d %d %d ", &num1, &num2, &num3);


avg = num1+num2+num3;

avg = avg/3;

printf("the average is:%f",avg);

}
dumb question: what to do after i entered the numbers in TC++ "run" window? because pressing the "Enter" button does nothing.






Report
Re: executing programs in Turbo C++ "run" window Posted by AsmGuru62 on 15 Sept 2009 at 3:57 AM
: hi,
: here is the program:
:
: /*file:avrage.c*/
: #include<stdio.h>
: #include<conio.h>
: 
: /* calculate the average of three numbers */
: void main()
: {
: 	int num1, num2, num3;
: 	float avg;
: 
: 	printf("enter 3 integer numbers:");
: 	scanf(" %d %d %d ", &num1, &num2, &num3);
: 
: 
: 	avg = num1+num2+num3;
: 
: 	avg = avg/3;
: 
: 	printf("the average is:%f",avg);
:         
: 	getch();
: }

: dumb question: what to do after i entered the numbers in TC++ "run"
: window? because pressing the "Enter" button does nothing.
:
:
:
:
:
:
:
Report
Re: executing programs in Turbo C++ "run" window Posted by earlyriser1 on 15 Sept 2009 at 9:18 AM
brilliant!!
thank you very much


2 basic questions:

1)is there any function that will except hitting "Enter", and not an actual character to display the average?

2)is there a way to clear the "run" window, and the "user screen" window, without restarting Turbo C++ ?
Report
Re: executing programs in Turbo C++ "run" window Posted by AsmGuru62 on 15 Sept 2009 at 4:46 PM
: brilliant!!
: thank you very much

:
: 2 basic questions:
:
: 1)is there any function that will except hitting "Enter", and not an
: actual character to display the average?
:
: 2)is there a way to clear the "run" window, and the "user
: screen" window, without restarting Turbo C++ ?
:

Question #1 I am not sure I understand. Did you mistype 'accept'? What exactly you need to do? Also, the average displayed BEFORE you hitting any keys. Also, you can easily input ENTER instead of any other character - it will work the same way.

Question #2.

Simply call function clrscr() and it will clear the screen.
Report
Re: executing programs in Turbo C++ "run" window Posted by earlyriser1 on 15 Sept 2009 at 11:34 PM
1# yes sorry - i mistyped 'accept'.
and for me the average does not display before i hit any keys. after i insert the numbers i must hit a letter key (doesn't matter which one) and then ENTER - only then will i see the average...

2# - thanks - it worked

Report
Re: executing programs in Turbo C++ "run" window Posted by AsmGuru62 on 16 Sept 2009 at 4:06 AM
Wow! You are correct!
I just tried this code on my TC 201 and indeed you need
to enter something before seeing the average value.

I found the cause, however.

The formatting string is " %d %d %d ".
Notice the blanks on both sides. Simply remove them.
The formatting string is now "%d %d %d". And the problem is gone!
It is most likely the bug in Turbo C itself.
I am not sure the C/C++ standard has anything to say about this behavior, so it is most likely a bug in TC. Well, it was long ago.

I have added some colors to your program.
Have fun!

/*file:avrage.c*/

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

 /* calculate the average of three numbers */
 void main()
 {
 	int num1, num2, num3;
 	float avg;

	textcolor (WHITE);
	cprintf("\r\nenter 3 integer numbers: ");
	textcolor (LIGHTGREEN);
	cscanf("%d %d %d", &num1, &num2, &num3);


 	avg = num1+num2+num3;

 	avg = avg/3;

	textcolor (YELLOW);
	cprintf("\r\nthe average is:%f",avg);

	bioskey (0);
	textcolor (LIGHTGRAY);
 }

If you want to know where all those functions come from - simply put cursor on a name of any function or constant, like YELLOW, and press CTRL+F1.
Report
Re: executing programs in Turbo C++ "run" window Posted by earlyriser1 on 16 Sept 2009 at 9:09 AM
Awesome! It worked!
Nice debugging skills man

And the colors are much better thank you...

You've been a great help man. Much much appreciated
Report
Re: executing programs in Turbo C++ "run" window Posted by AsmGuru62 on 17 Sept 2009 at 3:08 AM
You can also do graphics programs and it will all work in Win XP DOS box. Here is how to discover functions for it:
#include <graphics.h>

Then put a cursor on 'graphics.h' and press CTRL+F1 - it should give the list of functions in that header. Read on!
Report
Re: executing programs in Turbo C++ "run" window Posted by earlyriser1 on 17 Sept 2009 at 10:34 AM
Thanks, right on it!
Report
Gucci Mens Denim Jeans (Www.Edhardy4sale.Com) Posted by didi312 on 7 Oct 2009 at 7:35 AM

Cheap Men Gucci Jackets (Www.Edhardy4sale.Com) Wholesale Gucci Men's Jackets (Www.Edhardy4sale.Com) Discount Gucci Jackets For Mens

Coogi ED Hardy Urban Clothing (Www.Edhardy4sale.Com) Cheap Hip Hop Gucci Clothing Wholesale

Gucci Womens Sandals (Www.Edhardy4sale.Com)

Gucci Mens Denim Shorts (Www.Edhardy4sale.Com)

Gucci Mens Denim Jeans (Www.Edhardy4sale.Com)

Gucci Belts (Www.Edhardy4sale.Com)

Gucci Mens Short Sleeve Tee Shirts (Www.Edhardy4sale.Com)

Gucci Womens Short Sleeve Tees (Www.Edhardy4sale.Com)

Gucci Women Short Sleeve Polo Shirts (Www.Edhardy4sale.Com)

Gucci Short Sleeve Polos For Big Men (Www.Edhardy4sale.Com)
Report
Re: executing programs in Turbo C++ "run" window Posted by nathanpc on 20 Sept 2009 at 5:22 PM
Please, put the code tags!

Thanks!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.