The code does not allow input for the name? Why exactly?
I am missing something and keep going back and forth.
(its not done yet, I ran into this issue)
The code is blah blahed because of search engines to make it generic.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string captain;
int shipid,pods,proton,jetpack,oxygen;
//Intro
cout<<" Intro to prog"<<endl;
//Allows u to enter this then skips captains name and goes straight to pDDD sales.
Did I forget to close something? It has been a long day!!!!
cout<<" Please Enter blahblah ID or -999 to Terminate ";
cin>>shipid;
// Captain Name is John Smith
cout<<" Please Enter the Captain's Name " <<setw(15) << " ";
getline(cin,captain);
//Still playing w setw for aligning texts
cout<<" Please enter Fuel pDDD Sales " <<setw(15) << " ";
cin>>pods;
cout<<" Please Enter PP blahblah Sales ";
cin>>proton;
cout<<" Please Enter JJJ Sales ";
cin>> jetpack;
cout<<" Please Enter OXXX Sales ";
cin>> oxygen;
cout << endl;
cout<<" Exit Statement blah blah"<<endl;
cout<<" blahblah"<<setw(6)<<shipid<<endl;
cout<<" Captain's Name:"<<setw(4)<<captain<<endl;
cout<<" *********************************"<<endl;
system ("PAUSE");
return 0;
}
It does input name. What do you, as user, type after the last digit of the shipid number? Do you hit 'Enter'?
I bet you do. That enter creates a newline. That newline is not consumed by the line 19 and thus lurks there for the unsuspecting getline on line 23. "Up to next newline" is the task description of getline and that is exactly what it does. A very short line.
You have to decide what to do if a newline follows the shipid.
I type anything from 1-999 ( and hit enter) for shipid
(when I run it with visual C++ it doesn't allow you to enter the Captains Name unless I use cin.ignore(); for line 24. Then name part works but you can not input anything else besides shipid and captains name