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![]()
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().
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
sorry i dont understand what you mean![]()
Well, I can't read your mind, why not post the problem code?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
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');
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
I agree with sabastian
use
this will write the whole typed string into nameCode:cin.getline(name, 20, '\n')
Dev C++
Win XP/2k/98
I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!
He's lean he's keen... He's the spank machine!