简体   繁体   English

如何修复 c++ 不输出输入

[英]How to fix c++ not outputting the input

How to fix c++ not outputting the input I got no idea!如何修复 c++ 不输出输入我不知道! So please help me I am new to c++!所以请帮助我,我是 C++ 的新手!

#include <iostream>

using namespace std;

int main()
{

    std::cout << "Please type if you want pickup or delivery: ";

    string input;
    string pickup;
    string delivery;
    string address;

    if (input == "pickup")
    {
        cout << "What pizza do you want(press r for a random pizza and c for cheese pizza!): ";
        cin >> input;
    }

    if (input == "delivery")
    {
        cout << "Tell me your adress and i will deliver a random pizza to ur house: ";
        getline(cin,address);
        cin.ignore();
    }

    if (address == address)
    {
        cout << "Thx we will delivery the pizza to " << address << " tommorow at 3PM!" << endl;
    }

    return 0;
}

You are not asking for input...你不是要求输入...

std::cout << "Please type if you want pickup or delivery: ";

after this line you need to get the user to input either pickup or delivery在此行之后,您需要让用户输入取货或交货

ie IE

std::cin>>input;

next you need to swap getline(cin,address);接下来你需要交换getline(cin,address); and cin.ignore();cin.ignore(); arround.. currently you are asking for input and then clearing the buffer. arround .. 当前您要求输入,然后清除缓冲区。

also if (address == address) what are you trying to achieve here?另外if (address == address)你想在这里实现什么?

your code can be written like this你的代码可以这样写

#include <iostream>

using namespace std;

int main()
{

    std::cout << "Please type if you want pickup or delivery: ";

    string input;
    string pickup;
    string delivery;
    string address;
     cin>>input;
    if (input == "pickup")
    {
        cout << "What pizza do you want(press r for a random pizza and c for cheese pizza!): ";
        cin >> input;
    }

    if (input == "delivery")
    {
        cout << "Tell me your adress and i will deliver a random pizza to ur house: ";
         cin.ignore();
        getline(cin,address);
        cout << "Thx we will delivery the pizza to " << address << " tommorow at 3PM!" << endl;
    }

 
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM