11 Replies - 1640 Views - Last Post: 26 January 2011 - 09:19 AM Rate Topic: -----

#1 nghtprwlr99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-January 11

set up the 8 char variables

Posted 25 January 2011 - 05:58 PM

[How do you set up the 8 char variables to hold the digits of the phone number in main() and pass the variables to the functions by reference ?

Thanks Bill
Is This A Good Question/Topic? 0
  • +

Replies To: set up the 8 char variables

#2 Slumdog   User is offline

  • D.I.C Head

Reputation: 34
  • View blog
  • Posts: 116
  • Joined: 26-November 10

Re: set up the 8 char variables

Posted 25 January 2011 - 06:44 PM

Can you put some effort?

I'll give you a hint: You use a character variable; it would be better to use a std::string, though.
Was This Post Helpful? 1
  • +
  • -

#3 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: set up the 8 char variables

Posted 25 January 2011 - 06:54 PM

View PostSlumdog, on 26 January 2011 - 03:44 AM, said:

... I'll give you a hint: You use a character variable; ...


A character array perhaps. :)
Was This Post Helpful? 1
  • +
  • -

#4 Slumdog   User is offline

  • D.I.C Head

Reputation: 34
  • View blog
  • Posts: 116
  • Joined: 26-November 10

Re: set up the 8 char variables

Posted 25 January 2011 - 07:03 PM

View Post#define, on 25 January 2011 - 06:54 PM, said:

View PostSlumdog, on 26 January 2011 - 03:44 AM, said:

... I'll give you a hint: You use a character variable; ...


A character array perhaps. :)


I anticipated this reply. I was too lazy to change it to an array. :)
Was This Post Helpful? 2
  • +
  • -

#5 Guest_nghtprwlr99*


Reputation:

Re: set up the 8 char variables

Posted 25 January 2011 - 07:33 PM

[Define a function named ReadDials() that reads each digit/letter dialed into 8 separate char variables -----(DO NOT USE ARRAYS )----. All digits are sent back through parameters by reference.
Thanks bill

Sorry I seem so lazy, just trying to learn...
Was This Post Helpful? 0

#6 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: set up the 8 char variables

Posted 25 January 2011 - 08:35 PM

Are you using C or C++?

Are you able to declare eight separate char variables?

I take it you are struggling with creating the function.

If you create some code we will be able to tell where you need help.

This post has been edited by #define: 25 January 2011 - 08:36 PM

Was This Post Helpful? 0
  • +
  • -

#7 nghtprwlr99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-January 11

Re: set up the 8 char variables

Posted 25 January 2011 - 09:03 PM

Thank you so much, it's getting late here but I will post some tomorow. Thanks for you time and your kind advise. I appreciate it.
I am in C++
int read_dials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);


Bill
Was This Post Helpful? 0
  • +
  • -

#8 nghtprwlr99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-January 11

Re: set up the 8 char variables

Posted 26 January 2011 - 08:11 AM

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()  
{
   // the char variables for the 8 digits of the phone number
	int const numberDialed =0 ;
    int phoneNumber = 0 ;
	int numberOfDigits = 0 ;
    int read_dials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);
    int return_value ;
    int toDigit =  "" ;

    toDigit function for each of the 7 digits
    return_value = todigit(d1); --> return_value is assigned the d1 values so that it can be evaluated by the if statement below.
    if (return_value == -1)
    return return_value;

    return_value = todigit(d2);
   if (return_value == -1)
   return return_value;

   return_value = todigit(d3);
   if (return_value == -1)
   return return_value;
   cout << " Enter a phone number";
   cin >> phoneNumber ;

   cout << " You entered " << phoneNumber << endl;
     
	return 0 ;

}


This post has been edited by JackOfAllTrades: 26 January 2011 - 08:16 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: set up the 8 char variables

Posted 26 January 2011 - 08:16 AM

It appears the use of code tags is eluding you. If this:

:code:

is too complicated, please refer to the first link in my signature.
Was This Post Helpful? 0
  • +
  • -

#10 simeesta   User is offline

  • Deadly Ninja


Reputation: 221
  • View blog
  • Posts: 594
  • Joined: 04-August 09

Re: set up the 8 char variables

Posted 26 January 2011 - 08:33 AM

you have a function declaration inside main on line 11. Move it to BEFORE main.
You can use an array char myarray[8]; to store the digits instead of 8 seperate variables.

Should lines 15,16 be commented or what?

Why do you have 3 of these:
 if (return_value == -1)

???
Was This Post Helpful? 0
  • +
  • -

#11 nghtprwlr99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-January 11

Re: set up the 8 char variables

Posted 26 January 2011 - 08:35 AM

Cannot use arrays,
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: set up the 8 char variables

Posted 26 January 2011 - 09:19 AM

Please read the tutorial links in my signature.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1