473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Floating type problem with turbo c++

Parul Bagadia
188 100+
I just wrote a code for myself to clear certain things...........
When i made this program to execute in turbo c++ it didnt.....
it showed following error.
I have pasted the output after code is over.
But when i executed the same code in microsoft visual c++; it worked without showing any errors.
Can somebody tell me why that happened.
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void assign();
  4. void check();
  5. float c;
  6. void main()
  7. {
  8.  int choise;
  9.  do{
  10.     printf("\nEnter your choise from the given menu:\n 1.Assign\n 2.Check \n 3.Exit\n");
  11.     scanf("\n%d",&choise);
  12.      switch(choise)
  13.      {
  14.       case 1:
  15.          assign();
  16.          break;
  17.       case 2:
  18.          check();
  19.          break;
  20.       case 3:
  21.          break;
  22.      }
  23.    }while(choise!=3);
  24. }
  25. void check()
  26. {
  27. float i;
  28. printf("%f",&c);
  29. i=c+1;
  30. printf("\n%f",i);
  31. printf("\n%f",&i);
  32. }
  33. void assign()
  34. {
  35.  printf("\n Enter the value of c:\n");
  36.  scanf("\n%f",&c);
  37. }
  38.  
Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
1

Enter the value of c:
2

Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
2
Floating point error: Domain.
Abnormal program termination

Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
2
Floating point error: Domain.
Abnormal program termination

Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
1

Enter the value of c:
33.4

Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
2
Floating point error: Domain.
Abnormal program termination

Enter your choise from the given menu:
1.Assign
2.Check
3.Exit
Mar 4 '08 #1
1 7854
Laharl
849 Expert 512MB
Since c is never initialized with a value, it simply holds whatever was left over there from the last time that memory was used. Thus, when you use it in check() before calling assign(), it has a garbage value that isn't in the domain of allowable floating-point bit patterns and thus Turbo C++ throws an error. When you ran it the next time, it had a valid leftover bit pattern through sheer luck. In short, assign c to some default value, say, 0.0 when you define it.
Mar 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
7
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
4
by: Rajesh | last post by:
struct symbol { char ch; float probability; char *codeword; }; void get_user_input(struct symbol **sptr) { .....
8
by: neha | last post by:
hi Its been Given that Which error are you likely to get when you run the following program? main() { struct emp { char name;
16
by: scott | last post by:
I am looking for a copy of Turbo C 1.5 from 1987 for some historical research I'm doing into computing from that time period.
3
by: LSW | last post by:
I'm using Borland Turbo C++ 3.0 to develop an embedded system to shift data around a network. At the moment we receive a string of bytes over a serial line and reassemble them into floating point...
1
by: kumarsatish | last post by:
The following C program in Turbo c is given the following error " Floating point formats not linked abnormal program termination" #include<stdio.h> #include<conio.h> #include<math.h>...
26
by: y8ycgl | last post by:
i have a program that i made in my class in Turbo C++ on windows 95or98 i belive. it is made to solve for factorials. th problem is that : A) it puts it in exponents B) theres too many numbers to...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.