3

特定の製品が適合する車の型式と年式を考慮する必要があります。プログラムは、HTML のアウトラインとなるテキストを含むファイルを書き込みます。当社の Web ページに製品をすばやく追加できるように、重要な情報を正しい場所に挿入する必要があります。製品のカテゴリを区切るために switch ステートメントまたは if ステートメントを使用すると、入力がめちゃくちゃになり、質問の 1 つに答えることができません。「2008 - 2009 - 2010 - 2011」のような日付を取得する必要があるため、cin だけを使用することはできません。

これが私がこれまでに得たものです!これはただのレギュラーcinです、私はあなたがすぐにできることを試しgetlineました.私は昨日始めました.私はかなり新しいので、これが簡単な修正である場合は許してください.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void proinfo();

int main()
{
    //Sytem Information
    system("TITLE This is a Beta of My Product Information Template Version 0.0.2");

    //I'm using this as a welcome screen to inform users of new improvements on patches and other pertinent information to the users
    cout << "Welcome To My Product Information Template Maker!!! \n It Is 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 is the first menu the user sees where they have to choose what type 
        //of products users will be adding
        system("CLS");
        cout << "Welcome to My Product Information Template Version 0.0.0" << endl;

        cout << "Please select the number of the product" << endl;
        cout << "type you will be ading!\n" << endl;

        cout << "1.Fe - Fe2 Moldings" << endl;
        cout << "2.CF - CF2 Moldings" << endl;

        cout << "What would you like to 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 the Make of the molding" << endl;
            cin >> make;

            cout << "Please Enter the Model of the molding" << endl;
            cin >> model;

            cout << "Please Enter the Years this molding fits" << endl;
            cin >> year;

            cout << "You have just created a template for a(n)" << year << " " << make << " " << model << endl;
            cout << "Check My Documents For a file called Fe-Fe2template.txt" << endl;

            //Asks to quit or restart
            cout << "Would you like to make another 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 to quit or restart
            cout << "Would you like to make another 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()    
}
4

1 に答える 1

5

year[256] を string year に変更します。

cin >> 年を変更します。getline(cin、年);

行 cin.ignore(); を追加します。getline の前。

あなたの主な問題は、ストリーム演算子 >> がストリームに改行を残すため、 getline を使用しようとすると空の行が読み取られることです。ignore() は改行を噛み砕いて、期待する文字列を読み取らせます。

だから、これはあなたの方法で取得する必要があります。

cin.ignore();
cout << "Please Enter the Years this molding fits" << endl;
getline(cin, year);

他にもいくつかの小さな問題がありますが、それらを理解してください。最悪なのは、ループを終了するのを忘れることです。

if(getinput=="yes")
{
    cout << "Great, Lets keep working!" << endl;
   //End of If statement
}
else
{
    loop = 0;
    continue;
}
于 2011-05-11T03:02:48.570 に答える