C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #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,966 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 2 Days 52 m 24 sec
Reputation Power: 189
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: 12
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

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap