GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Apr-2007, 22:17
rbroller815 rbroller815 is offline
New Member
 
Join Date: Apr 2007
Posts: 11
rbroller815 is on a distinguished road

help


how do i creat a function to prompt a user to enter a value A. check it to b zero and if it is then return an error and reaske to enter. if it isnt zero then return it. how do i write the loop
  #2  
Old 02-Apr-2007, 00:33
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: help


Using what you already know about
  • Functions
  • Input
  • IF statements
  • WHILE loops
  • Return values
give it a try and we can help you. Do what that Yellow on Red post titled Read This explains.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #3  
Old 03-Apr-2007, 18:00
davis
 
Posts: n/a

Re: help


Quote:
Originally Posted by rbroller815
how do i creat a function to prompt a user to enter a value A. check it to b zero and if it is then return an error and reaske to enter. if it isnt zero then return it. how do i write the loop

CPP / C++ / C Code:
#include <iostream>

using namespace std;

int GetIntFromUser()
{
    int integer = 0;
    while( integer == 0 )
    {
        cout << "Enter a non-zero integer: ";
        cin >> integer;
    }
    return integer;
}

int main()
{
    int i = GetIntFromUser();
    cout << "User entered: " << i << endl;
    return 0;
}

Output:

Code:
Enter a non-zero integer: 0 Enter a non-zero integer: 192182 User entered: 192182

:davis:
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.