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 November 25th, 2004, 10:32 PM
oi_son oi_son is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 oi_son User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
-

-Deleted-

Last edited by oi_son : November 25th, 2004 at 10:48 PM. Reason: -

Reply With Quote
  #2  
Old November 25th, 2004, 10:42 PM
fisch's Avatar
fisch fisch is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2004
Location: Frostbite capital of the world
Posts: 542 fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 16 h 58 m 34 sec
Reputation Power: 10
Ask the user for there choice probably by giving them 2 options allowing them to enter a number for the option they choose. Then use a "switch" statement or a "if" statement to output the answer in the format the user chose.

Reply With Quote
  #3  
Old November 25th, 2004, 11:31 PM
Dictionary's Avatar
Dictionary Dictionary is offline
Registered User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Nov 2004
Location: Ottawa, ON
Posts: 2,059 Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level)Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level)Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level)Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level)Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level)Dictionary User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 10 h 50 m 52 sec
Reputation Power: 48
so it might look like

PHP Code:
 int choice;
cout<<"There are two choices\n float and integer\n  press 1 for float, 2 for integer";
cin>>choice;
if (
choice==1){
 
//code goes here
}
if else (
choice==2){
 
//code
}
else
break; 

Reply With Quote
  #4  
Old November 25th, 2004, 11:47 PM
fisch's Avatar
fisch fisch is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2004
Location: Frostbite capital of the world
Posts: 542 fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level)fisch User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 16 h 58 m 34 sec
Reputation Power: 10
i'd suggest changing choice to a char instead of having it as an int. That way if the user enters are char by mistake it won't kill the program. You'd then have to change:

if (choice==1)

to:

if (choice=='1');


if else (choice==2){
should be

else if

And you might want to include a loop in there so if the choice entered is not 1 or 2, the user is asked again.

Code:
char choice='*';
while (choice!='1'&&choice!='2'){
   cout<<"There are two choices\n float and integer\n  press 1 for float, 2 for integer";
   cin>>choice;
}//end while


edit:

you should probably rewind(stdin) after your cin>>choice to clear the buffer.

Last edited by fisch : November 25th, 2004 at 11:57 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Integer or Float selection

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