| | |
Homework Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
My problem with the program listed below is when the question asked for the title of the book and you type in more than one word with white spaces inbetween the words like "History of Me" it will skip the next question. Any help will be appreciated.
#pragma hdrstop
#pragma argsused
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
char date[8];
int quantity;
char isbn[13];
char title [20];
float bookprice = 0.00;
//Sales slip information to be entered by user
cout << "Please enter the date in mm/dd/yy format:\n" ;
cin >> date;
cout << "Please enter the quantity being purchased:\n" ;
cin >> quantity;
cout << "Please enter the ISBN number for the book:\n" ;
cin >> isbn;
cout << "Please enter the title of the book:\n" ;
cin >> title;
cout << "Please enter the price of the book:\n" ;
cin >> bookprice;
system("pause");
return 0;
}
#pragma hdrstop
#pragma argsused
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
char date[8];
int quantity;
char isbn[13];
char title [20];
float bookprice = 0.00;
//Sales slip information to be entered by user
cout << "Please enter the date in mm/dd/yy format:\n" ;
cin >> date;
cout << "Please enter the quantity being purchased:\n" ;
cin >> quantity;
cout << "Please enter the ISBN number for the book:\n" ;
cin >> isbn;
cout << "Please enter the title of the book:\n" ;
cin >> title;
cout << "Please enter the price of the book:\n" ;
cin >> bookprice;
system("pause");
return 0;
}
Did you see this on your way in?
•
•
•
•
Originally Posted by forum title page
Announcement: Please use BB Code and Inlinecode tags
cscgal (The Queen of DaniWeb)
This behavior is expected, because the operator >> of cin reads input in his stream until a end-of-line or a whitespace is found. So, the next operator>> call finds remaining input (the other words after the whitespace) in the cin buffer and takes the data. If you want to prevent this situation, you need to truncate the input to the first whitespace or the end-of-line character. You can do it by doing a fscanf call like this:
fscanf(stdin, %s\n, your_string_variable);
This is a C-style way to do it and I would like to see other ways, C++ oriented, to prevent a whitespace in the input.
fscanf(stdin, %s\n, your_string_variable);
This is a C-style way to do it and I would like to see other ways, C++ oriented, to prevent a whitespace in the input.
cin does not read white spaces.
use cin.getLine(...), or cin.get(...) or getline(...); They don't skip spaces.
use cin.getLine(...), or cin.get(...) or getline(...); They don't skip spaces.
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- Need help with Computer Science homework (Computer Science)
- Dynamic memory allocation homework (C++)
- Homework Help!! Priority Queue ?? (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: VS IDE auto-indent formatting
- Next Thread: Can anyone explain to me how to set up a flag?
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






