Hello Programmers! I am working on a C++ phone number class. The class has overloaded stream manipulators, cin and cout for output. It has three private members: areaCode, exchange, and line, strings that represent the numbers that are used in a telephone call. It is supposed to default to (000) 000-0000 with the default constructor. Then, the user is able to manipulate the object by inputting in a telephone number of the specified format: (xxx) xxx-xxxx. My overloaded operator 'cin' is supposed to check for various errors on the user's fault, and set the failbit if the inputted number does …

Member Avatar
Member Avatar
+0 forum 3

Hi guys, I have a class called Account with variables called Balance and Status. The Member Name is given by the User through cin and represents an the Account Number. How can I diynamically create an object through cin and give their variables a value through cin? I have been looking for hours and just cannot figure it out. Any help is appreciated. Thanks guys. Here's my code. It won't compile as I'm just trying to show what I want to do. class Account { public: char Status; int Balance; }; int main() { int Nmbr; int Bal; char Stat; …

Member Avatar
Member Avatar
+0 forum 12

Hellp programmers! I am working on a program that uses two objects of a custom class template List [which is a linked list, with each item pointing to the next] and concatenates them. Initially, I need to input numbers into my main function, so I have two sets of while loops (while an EOF sequence is not entered) to enter a number into the loop. Here's my code so far: // Program that takes two linked list objects and concatenates #include <iostream> #include "List.h" using namespace std; int main() { //create two linked lists List<int> firstList; List<int> secondList; //add values …

Member Avatar
Member Avatar
+0 forum 12

when converting iget erros especially in the cin parts because they are automatically passed by something #include<iostream> #include<conio.h> #include<math.h> using namespace std; int p=1; class Bank { public: char name[50],address[90],type; double ein_betrag, aus_betrag; double balance; int costumernr, accountnr, birth, tel; public: void newcostumer(); void newaccount(); void costumerdel(); void accountdel(); void deposit(); void withdraw(); void accountinfo(); }; void Bank::newcostumer() { cout<<"\n Enter your name : " << endl; cin>>name; cout << " Enter your address: " << endl; cin >>address; cout << " your tel nr please: " << endl; cin >>tel; cout << " Enter your gebdatum: " << endl; …

Member Avatar
Member Avatar
+0 forum 2

I am getting an error on this code. Is it to do with whats in the while loop? How do i get it working? Basically i want to be able to take in letter or number variables, and each would output something, and if they type exit it breaks out of the loop. #include <string> string input; while (input != 'exit') { cout << "OS#: "; getline (cin, input); if (input == 'a') { cout << "hello"; } }

Member Avatar
Member Avatar
+0 forum 2

In the last few days, I have noticed a very old thread ... resurrected ... about a non-standard C getline function. To all who may like a C readLine function ... a C function that reads in a dynamic C string of any length ... a function with a similar feel to the C++ getline function ... please feel free to use readLine.h (to access readLine) ... or readWord.h (to access readWord) These are freely available at: [For ... readLine and readWord ... Click Here](http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864)

Member Avatar
+0 forum 0

#include<iostream> using namespace std; int main() { int len1; cout<<"please enter the length of arrayn 1"; cin>>len1; cout<<"creating array now"; int *arr1= new int[len1]; cout<<"please enter the elements now"; for(int i=0;i<len1;i++) { cin>>arr1[i]; cout<<endl; } return 0; cout<<arr1; delete [] arr1; } In the above code, the program stops execution after the first cin.(i know that the variable needs to be initialized first) Q1) why do we need to initialize the variable first?? Should it not take some garbage value or NULL?

Member Avatar
Member Avatar
+0 forum 4

Hi everyone, I am writing a program that converts numbers to words and vice-versa, like typing on a older cellphone. The user enters as many messages as he wants in numbers and/or text. The first character of the messages indicates what the remaining string is: numbers or letters. I can't seem to find a way to get that first character without errors spawning everywhere. I have tried using cin and getline. If someone could explain what I am doing wrong, that would be great. Here is what I have: #include<iostream> #include<string> #include<sstream> using namespace std; int main() { //Declare variables …

Member Avatar
Member Avatar
+0 forum 3

User is supposed to type an input, and if it's not an integer, the user needs to type another. This repeats 3 times for 3 inputs which go inside an array. The integer checking works, but the problem is that when i display the 3 integers, they are all the same number (the first correct input). Idk what's wrong. I've tried cin.clear() and cin.sync()... for(int i=0;i<3;i++){ cout<<"Enter your "<<text[i+6]<<": "; cin.sync(); cin.clear(); cin>>inInt[i]; if(!cin){ cout<<"\nPlease enter a valid integer."; i--; system("pause");} system("cls");}

Member Avatar
Member Avatar
+0 forum 1

I am having trouble getting MS Visual C++ to recognize my input for the 2nd getline I have listed. It already recognizes getline(cin, firstName) and allows for input, but won't recognize the second instance of getline. When the program gets to that line of output, it bunches the next two cout statements together like this: Tell us the name of the item you wish to buy? How many of these would you like to purchase today? The code should give the user a chance to enter the name of the item and allow for spaces, but it shows the output …

Member Avatar
Member Avatar
+0 forum 1

excuse me but can someone teach me how to get a string with space example : this author i need to get the codes on how to get that thank you

Member Avatar
Member Avatar
+0 forum 3

I have this function: void read(){ int id; string desc; string title, type; cout<<"Movie's id: "; cin>>id; cout<<"Movie's title: "; cin>>title; cout<<"Movie's description: "; getline(cin, desc, '\n'); cout<<"Movie's type: "; cin>>type; cout<<"You have typed in: " <<id <<" " <<title <<" " <<desc <<" " <<type <<".\n"; } and my problem is that in the desc field, when I must insert something, it skips over, passing to the type field, not letting me insert anything. I've tried in another project only with the `getline(cin, desc, '\n')` and it worked, it took all the line, but here it just skips the …

Member Avatar
Member Avatar
+0 forum 2

Hi, I have a problem with a the imput of some data on a program Im making (FYI new in c++, homework). So basicly the progrma I have is to imput diferent type of data, this is what im doing. (Im using codeblock 8.02 in Ubuntu 10.04 ) #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <cmath> using namespace std; struct person { int cod; char name[40], cid[15]; }client[100]; main() { int opc,exit serch, c=0, i, e; while(exit!=1) { cout<<"1. Imput data"<<endl; cout<<"2. Out data"<<endl; cout<<"3. Exit"<<endl; cout<<"Enter an opcion: " cin>opc; system("clear"); swith(opc) { case 1: cout<<"Enter code: …

Member Avatar
Member Avatar
+0 forum 5

hi, I have this code: [CODE]#include<iostream> #include<cstdio> #include<sstream> using namespace std; int main (char argc) {        float n1;        char operators;        string n2;        float n2_act;        float ans;        cin >> n1;        for(;;)        {                  cin >> operators;                  cin >> n2;                                                    …

Member Avatar
Member Avatar
+0 forum 19

Hello everybody! I'm participating in a competition, and I just finished my program. It doesn't really matter what it does, and how. I have encountered a bug I think. I'd appreciate every kind of help, because with the problem, my solution fails for the test file. I have to read N pieces of data, formatted "STRING_space_STRING_space_INT" Obviously I used cin >> from >> to >> cost; When I am finished with reading, I'm waiting for another type of input in another while loop - no COUT used there neither. The problem : after the last reading from the first sequence, …

Member Avatar
Member Avatar
+0 forum 8

hi! can someone help debug my codes? getline() works properly in my main() but if i'm putting it to another function, it ignores the first getline() w/o entering any words and goes to the 2nd getline. my program works like this: i have a menu() that lets the user to choose a category [easy-'e', ave-'a', hard-'h']. for example, if the user chose the letter 'e' it will jump to the easy(). and as soon as i entered the letter 'e', it goes straight to player 2 or the 2nd getline. the easy() consists of two getline (string answers for player …

Member Avatar
Member Avatar
+0 forum 3

if i hav to input time of clock as formatted style(HH:MM:SEC) using cin how can i write its code???? a question from @robert lafore(sams publication) . hope to get a best answer soon :)

Member Avatar
Member Avatar
+0 forum 2

When I run my program it ignores the cin and goes into an infinite loop. It acts as though the cin.ignore() isn't working. [CODE] int getInput(int tries){ int numGuess = 0; cin >> numGuess; cin.ignore(); validate(numGuess, tries); return 0; } int validate (int input, int tries){ if (input <1 || input >100){ cout << "Please enter a decimal integer between 1 and 100: "; getInput(tries); } return NULL; }[/CODE]

Member Avatar
Member Avatar
+0 forum 14

My program generates a list of random or pseudo random numbers between a certain range specified by the user through the console. My problem is when the user, or in this case myself, tries to generate a random number list specified by entering true(1) in the console the output is always false(0). I cant seem to figure this out. Any help would be great. The program has four files. utility.h just contains all the include statements, filer.h, filer.cpp has the code to make the file of random numbers, and test.cpp has the main function to test the code with the …

Member Avatar
Member Avatar
+0 forum 3

Need a little help, I'm trying to run a program that asks the user to enter an integer between 1-50. If given a number between 1 and 50 then echo number then add all integer between 1 and integer entered if user enter an integer not between 1 and 50 then just echo the number and ask the user for another number if a noninteger is enter i need the program not to go into and fail state, instead clear the noninteger and ask the user for another integer. To exit the loop you must press cntl-Z. This is what …

Member Avatar
Member Avatar
+0 forum 1

Hi, I'm very new to Java (started today, though I have 1.5 years in c++) and I've now read a little bit about Java, the thing that I can't find is how to take user input from the keyboard through a console window... How can you go about do that? I'm looking for something like [ICODE]std::cin[/ICODE] in c++. That however doesn't seem to be available in Java. Thanks, jt

Member Avatar
Member Avatar
+0 forum 3

How Would i be able to check for valid input on cin or getline heres what i have [CODE] #include <iostream> #include <string.h> using namespace std; int main() { string word; getline(cin, word); cout << word; system("PAUSE"); return EXIT_SUCCESS; } [/CODE] what i mean by valid input is either if the user enters an integer when i wanted a string or if the user enters nothing and causes weird results

Member Avatar
Member Avatar
+0 forum 13

Well I am coding a small intermediate program to help me with learning c++ , and i am wondering how to check for blank input to cin >> string heres what i have [CODE]string name; cout << "Enter You're Name: "; getline(cin, name); [/CODE] and if i just hit enter without typing any name the program just stays blank it is a console app btw

Member Avatar
Member Avatar
+0 forum 3

I am just having trouble with the beginning stages here. I am just very confused on different syntax terms. I have a book here "Microsoft Visual C++.net" with all the installation and whatnot with it. It doesnt use the normal cin and cout but used Console::WriteLine and what not. Is this still considered c++ or it another form or type? Does it matter at the beginning when I open a file if I go to console application or something else? It seems to be very closely realted but different in some other ways, like using the find function does not …

Member Avatar
Member Avatar
+0 forum 3

The End.