473,399 Members | 3,656 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,399 software developers and data experts.

Validate floats

I have to validate s floats thru a function , but the validation have to be don with a string of 20 characters ....

Any idea how to do thatvalidation floats?

Any help will be very appreciated !!!

This is the code so far :


#include <iostream>
#include <cstdlib>
using namespace std;

struct project
{
float latitude;
float longitud;
float time;
float distance;
float altitude;
// float latitude;
// float longitude
};

struct projectone
{

project source;
project travel;
project target;
float speed;
float azimuthal;
float equatorial;
};

bool getfloat (float *);

void main()

{
projectone projectile [100];
bool validata;
float value= 0.0;



do
{
cout<< "Enter the Launch speed :";
validata=getfloat(projectile.speed);

if (!validata)
{
cout << "Invalid Input .Try again...\n";
}
}while (!validata);

do
{
cout<< "Enter the Launch azimuthal angle :";
validata=getfloat(projectile.azimuthal);

if (!validata)
{
cout << "Invalid Input .Try again...\n";
}
}while (!validata);

do
{
cout<< "Enter the Launch equatorial angle :";
validata=getfloat(projectile.equatorial);

if (!validata)
{
cout << "Invalid Input .Try again...\n";
}
}while (!validata);

` do
{
cout<< "Enter the source latitude :";
validata=getfloat(projectile.source.latitude);

if (!validata)
{
cout << "Invalid Input .Try again...\n";
}
}while (!validata);

do
{
cout<< "Enter the source longitude :";
validata=getfloat(projectile.source.longitude);

if (!validata)
{
cout << "Invalid Input .Try again...\n";
}
}while (!validata);





}

// function to validate

bool getfloat (float *value)
{
int i;
bool noerrors=true;
i=0;


if (*value <
{
Dec 2 '06 #1
1 3159
horace1
1,510 Expert 1GB
you can validate float input with code such as
Expand|Select|Wrap|Line Numbers
  1. float getFloat()
  2. {
  3.       float f;
  4.       while(! (cin >> f))        // attempt to read a float
  5.           {             // if error, ask again
  6.            cout << "error, please reenter ? ";
  7.            cin.clear();           // clear error
  8.            cin.ignore(100,'\n');  // remove faulty characters from line
  9.           }
  10.       return f;              // OK, return value
  11. }
  12.  
if the user enters invalid characters the message will be displayed and they can enter again
Dec 2 '06 #2

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

Similar topics

8
by: Tom | last post by:
Has anyone ever seen a IComparer for floats the returns magnitude. i.e. instead of returning -1, it would return -5. To let you know HOW different the two numbers are. obviously for int it is a -...
8
by: Madhusudan Singh | last post by:
Is it possible to convert a very long list of strings to a list of floats in a single statement ? I have tried float(x) and float(x) but neither work. I guess I would have to write a loop if...
3
by: freelanceinaz | last post by:
My problem page is at http://girlschorus.org/test.html I have a container with a relatively positioned graphic at the top, then two floats which are relatively positioned (for a a two-column...
11
by: Steve | last post by:
I'm trying to create a list range of floats and running into problems. I've been trying something like: a = 0.0 b = 10.0 flts = range(a, b) fltlst.append(flts)
13
by: yb | last post by:
Hi, Is there a CSS method to clear a float such that it aligns with the left content edge. For example: X X X X X X X X
9
by: Thomas Nelson | last post by:
I want to generate all the fractions between 1 and limit (with limit>1) in an orderly fashion, without duplicates. def all_ratios(limit): s = set() hi = 1.0 lo = 1.0 while True: if hi/lo not...
16
by: luca bertini | last post by:
Hi, i have strings which look like money values (ie 34.45) is there a way to convert them into float variables? everytime i try I get this error: "numb = float(my_line) ValueError: empty string...
1
by: donpro | last post by:
https://testbed.odysseyshipping.com/index.php This is driving me nuts. I've spent much time trying to style this page footer but because I cannot set widths using "display: inline". I've tried...
0
by: Matthieu Brucher | last post by:
2008/11/5 L V <somelauw@yahoo.com>: Hi, I don't think the Python developers list is th best list to post this kind of question. What version of Python did you use for this test? Matthieu
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.