C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
CIO Insight
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Ziff Davis Enterprise Virtual Tradeshows: Hot Topics, Cutting Edge Technology, Real-time Networking among IT Professionals. Learn more
  #1  
Old March 6th, 2002, 10:00 PM
nepali nepali is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 3 nepali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
determining integer/non-integer value

hi,
how do i write a program which determines whether the value entered is integer or non-integer by using only control structures.
thanks

Reply With Quote
  #2  
Old March 7th, 2002, 02:39 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
i have no idea what you mean by "control structures".

but you can determine if a string is float by testing for the "." eg....
and you can test for the int-value being "0" and it not being the string "0".
could you please post more information about your specific problem?
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old March 7th, 2002, 10:07 PM
nepali nepali is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 3 nepali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sorry about being unclear....
what i wanted to do is
check the user entered value & see whether it's an integer or non-integer....
i'm allowed to use only if,for & while (control structures) & only allowed to use <iostream> or <iostream.h>

thanks for the effort

Reply With Quote
  #4  
Old March 7th, 2002, 11:22 PM
Lord MJ Lord MJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Posts: 34 Lord MJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 2 sec
Reputation Power: 7
Send a message via AIM to Lord MJ Send a message via Yahoo to Lord MJ
Basically loop through the string and if you find a character that's not '0' - '9'

return false.

Reply With Quote
  #5  
Old March 8th, 2002, 01:59 AM
nepali nepali is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 3 nepali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
complete assignment

maybe it'll make more sense if i explain the whole thing...

i want to constantly ask the user whether he/she wants to enter a value(y/n)

if 'y'...
i want to test the value for integer/nonInteger & even/odd & add to the counter accordingly....
if 'n'
if dispalys
1)no. of values entered
2)odd values entered
3)even values entered
4)sum
5)average
6)integer values entered
7)nonInteger values entered


here's what i have so far

#include <iostream.h>


void main()
{
int value,sum=0,average=0;
char response;
int valueCount=0, intCount=0, nonIntCount=0;
int evenCount=0, oddCount=0;

cout <<"\nDo you want to enter a value? (y/n): ";
cin >>response;

while ((response|32)=='y'){
cout<<"\nEnter your Value: ";
cin >>value;
sum=sum+value;

valueCount=valueCount+1;

if (value%2==0)
evenCount=evenCount+1;

else oddCount=oddCount+1;

cout<<"\nDo you want to enter a value? (y/n): ";
cin>>response;
}

average=sum/valueCount;

cout<<"\nThe number of Values you entered is: "
<<valueCount;
cout<<"\nThe sum of all the values you entered is: "
<<sum;
cout<<"\nThe average of the values you entered is: "
<<average;
cout<<"\nThe number of interger values you entered is: "
<<intCount;
cout<<"\nThe number of non-integer values you entered is: "
<<nonIntCount;
cout<<"\nThe number of even values you entered is: "
<<evenCount;
cout<<"\nThe number of odd values you entered is: "
<<oddCount<<endl<<endl;
}

p.s. i've been able to test the value for odd/even if it' s an integer value but changing it to float '%' doesn't seem to work


thanks for all the help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > determining integer/non-integer value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway