473,385 Members | 1,736 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.

a problem with the validty of my tax program

ok not sure how to accomplish my goal but's it's simple i want the program to ask if 125 was the correct amount entered but im not sure what is the simplest way to accomplish that i cant seem to get while and if to work. the program hangs on the if i know where the chack should go in the codde but i cant figre it out any suggestions would be helpful






/code
#include <stdio.h>
int main (void)
{

float Tax[3]={7.25, 7.5, 7.75}; //this float is the number that are used for the tax wiht the differnt places

float A = 0.0f; // this is the price of the item that will be used to find tax

int B = 0; // this is will pick the data that will be muiltply the tax
char ANS = ' ' ;


printf("Enter price of item: "); // this will be disply on the screen

scanf("%f", &A ); // this is where the price will be assigned to the a value

printf( "You enter %.2f, correct?\n" ,A) ;

scanf ("%s", ANS);


printf("Stores: (1) Delmar, (2) Encintas, (3) La Jolla? "); // this denots what tax percentage will be used

while ((B < 1) || (B > 3))
{ //this is to set the number and display the enter number
scanf("%i", &B ); //u
if ((B < 1) || (B > 3))
printf (" Enter the number associated to the store: "); //this message will appear until a number will be pressed
} // while
printf("The sales tax is %.2f" , A*(Tax[B-1]/100)); //


return 0; //

} // main
Mar 11 '08 #1
2 1117
gpraghuram
1,275 Expert 1GB
The problem is in the line where you read a char
Expand|Select|Wrap|Line Numbers
  1.  
  2. //scanf ("%s", ANS); change this to
  3. scanf ("%s", &ANS);
  4.  
  5.  
Raghuram
Mar 11 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
Generally, you cannot use operators like ==, !=, >, <, <=, >=, etc wth floating point numbers.
Due to the automatic rounding, these operators may report a condition as true when the numbers
are only close in value.

Google for Floating Point Arithmetic or read IEEE 754 standard specification for details.

To compare two floating point numbers, you have to establish a sigma error tolerance.

Expand|Select|Wrap|Line Numbers
  1. if (fabs(i - j) < 0.000001) { ... // almost equal }
  2.  
Mar 11 '08 #3

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

Similar topics

0
by: Slavik | last post by:
All libraries were installed (precompiled) This is FreeBSD 5.1 installed zlib, installed jpeg and png libraries (in default directories) GD 2.0.11 source is in /usr/gd-2.0.11 (compiled and...
6
by: Simon Foster | last post by:
Hi all, Has anyone seen the follwoing message on the Windows platform when tring to use Tk? --- >>> import Tkinter >>> root = Tkinter.Tk() Traceback (most recent call last):
0
by: ex laguna | last post by:
I have run into this problem below with py2exe version 0.5.0 and python 2.3.3. Does anyone know a solution or workaround for this? Thanks much! ## Begin of test.py import shelve f =...
3
by: fastwings | last post by:
mm the code //////makemenu.h//// class menu { public: int op; pmenu(int op,int sub = 0) { switch op {
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
2
by: subsanta | last post by:
My computer has so many problems and ive looked around on the internet and ive managed to fix some of them. I know that i have a few viruses on my computer, but i cant get rid of them, in one case i...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.