hello
im a bit of a newbie and i have a program in c++ and it asks questions, where u live, etc. when i type in an answer with a space in it, it skips the following question.
does anyone know how to combat this problem?
thanks in advance :)
Printable View
hello
im a bit of a newbie and i have a program in c++ and it asks questions, where u live, etc. when i type in an answer with a space in it, it skips the following question.
does anyone know how to combat this problem?
thanks in advance :)
If you're using scanf(), it's because it stops reading up to the next space (cin may do that too). Use fgets(), or cin.getline().
sorry i dont understand what you mean :confused:
Well, I can't read your mind, why not post the problem code?
This is the beggining part of it. I get problems when i want to enter spaces in the answersCode:#include <iostream> // This list defines what 'extras' are to be used within the program
#include <string>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main ( ) {
char manager[20]; // This list assigns the indentifiers with data types
char products[5][20];
float prices[5];
char suburb [20];
float Total = 0; // Defines Total's current value as '0'
char state [20];
int items, num;
char terminalid [8];
char eftpos [20];
char cardnumber [20];
char enter [24];
cout<<"Welcome to the Receipt Generator" << endl;
cout<<"Press any key and enter to begin..."; // This feature allows the user to choose when he/she is ready to start the program
cin>>enter;
system("cls"); // This command clears the screen for a more user-friendly appearance
cout<<"Enter the suburb of the store (upper case and no spaces please) > ";
cin>> suburb; // The user enters the suburb with the knowledge that it will be printed on the receipt
cout<<"Enter the state that the store is in (Upper case) > ";
cin>> state; // The user enters the state
ive had to write no spaces please because of the systems inability to handle spaces in the answers
Both cin and scanf use a space as a terminator, so it will only read up to the space. To get past this use cin.getline().
cin.getline(suburb, 20, '\n'); // << safest
or:
cin.getline(suburb, '\n');
I agree with sabastian
use
this will write the whole typed string into nameCode:cin.getline(name, 20, '\n')