2 Replies - 333 Views - Last Post: 27 January 2018 - 02:19 PM Rate Topic: -----

#1 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-January 18

value returning functions and while loops problem

Posted 27 January 2018 - 02:16 PM

So the problem i'm having is how would i incorporate a while loop into the value returning function?
This is the first part of my assignment, i just don't know what to put down below outside the main:

a. Prompt the user to input two positive integers. Variables: firstNum and secondNum (firstNum must be less than secondNum) (use while loop); create a user-defined function called validateUserInput() to validate the user's input. Use Call-by-Value. validateUserInput() is a value returning function.

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

bool validateUserinput (int firstNum, int secondNum);

int main ()
{
int firstNum ;
int secondNum ;
int Square= 0;
int sumEven = 0;

int counter;
char ch;

bool t = true;
    //a
    cout << "Enter two positive numbers. " << endl;
    cout << "The first number must be less than the second number you enter" << endl;
    cout << "Enter numbers: ";


    while (t)
    {
        cin >> firstNum >> secondNum;

        if (firstNum < secondNum && firstNum >= 0)
        {
            t = false;
        }

        else if (firstNum > secondNum)
        {
            cout << "First number must be less than the second number! \n";
            cout << "Please try again. \n \n";
            cout << "Enter two positive numbers. \n";
            cout << "First number must be less than the second number \n";
            cout << "Enter numbers: ";

        }

        else
        {
            cout << "No negative numbers! \n";
            cout << "Please try again. \n \n";
            cout << "Enter two positive numbers. \n";
            cout << "First number must be less than the second number \n";
            cout << "Enter numbers: ";
        }
    }

    cout << endl;

bool validateUserinput (int firstNum, int secondNum);
{
}




Is This A Good Question/Topic? 0
  • +

Replies To: value returning functions and while loops problem

#2 jimblumberg  Icon User is offline

  • member icon

Reputation: 5466
  • View blog
  • Posts: 17,018
  • Joined: 25-December 09

Re: value returning functions and while loops problem

Posted 27 January 2018 - 02:19 PM

Quote

how would i incorporate a while loop into the value returning function?

A while loop is the same no matter what function it happens to be in.



Jim
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 14036
  • View blog
  • Posts: 56,156
  • Joined: 12-June 08

Re: value returning functions and while loops problem

Posted 27 January 2018 - 02:19 PM

Would it make sense to have the while loop around each of the inputs, and the condition be a call to your function?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1