c++ - getline wont work in switch and cin does not take the data appropriately? Can anyone help? -


hey guys, im working on project job, cant seem figure out.

i need take in make model , years of car particular product fits. program going write file text in outline of html need crucial information inserted correct spots able add products our web page. when use switch statement or if statements separate categories of products, input gets messed , not let me answer 1 of questions. can't use cin because need take dates "2008 - 2009 - 2010 - 2011"

here i've got far! 1 regular cin, have tried getline c started yesterday , i'm pretty new forgive me if easy fix, cant find anything.

#include <iostream> #include <string> #include <fstream>  using namespace std;  void proinfo();  int main() {     //sytem information     system("title beta of product information template version 0.0.2");      //i'm using welcome screen inform users of new improvements on patches , other pertinent information users     cout << "welcome product information template maker!!! \n still in development" << endl;     cout << "\n\nworking features are:" << endl << "\t-none\n" << endl;     system("pause");     system("cls");     proinfo(); }  void proinfo() {     //declare variables here     int loop(1), protype;     char make[256], model[256], year[256];     string getinput;      while(loop==1)     {         //this first menu user sees have choose type          //of products users adding         system("cls");         cout << "welcome product information template version 0.0.0" << endl;          cout << "please select number of product" << endl;         cout << "type ading!\n" << endl;          cout << "1.fe - fe2 moldings" << endl;         cout << "2.cf - cf2 moldings" << endl;          cout << "what do? ";          cin >> protype;          if(protype==1)         {             //fe - fe2 molding             system("cls");              cout << "you have selected" << endl;             cout << "fe - fe2 moldings\n" << endl;              cout << "please enter make of molding" << endl;             cin >> make;              cout << "please enter model of molding" << endl;             cin >> model;              cout << "please enter years molding fits" << endl;             cin >> year;              cout << "you have created template a(n)" << year << " " << make << " " << model << endl;             cout << "check documents file called fe-fe2template.txt" << endl;              //asks quit or restart             cout << "would make tempalte?" << endl;              cin >> getinput;              if(getinput=="yes")             {                 cout << "great, lets keep working!" << endl;                 //end of if statement             }              system("pause");         }          if(protype==2)           {             //cf - cf2 molding             system("cls");              //asks quit or restart             cout << "would make tempalte?" << endl;              cin >> getinput;              if(getinput=="yes")             {                 cout << "great, lets keep working!" << endl;                 //end of if statement                                }              system("pause");              //end of protype switch statement                        }          //end of while loop                   }     //end of proinfo()     } 

change year[256] string year;

change cin >> year; getline(cin, year);

add line cin.ignore(); before getline.

your main problem stream operator >> leaves newline in stream when try use getline reads empty line. ignore() chew newline , let read string expect.

so should on way.

cin.ignore(); cout << "please enter years molding fits" << endl; getline(cin, year); 

you have other small problems you'll figure them out. worst forgetting terminate loop.

if(getinput=="yes") {     cout << "great, lets keep working!" << endl;    //end of if statement } else {     loop = 0;     continue; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -