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

  • 本文关键字:输出 何修复 c++ c++
  • 更新时间 :
  • 英文 :


如何修复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;
}

您没有要求输入…

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

在这行之后,您需要让用户输入拾取或交付

ie

std::cin>>input;

接下来你需要交换getline(cin,address);cin.ignore();。当前您正在请求输入,然后清空缓冲区。

if (address == address)你想达到什么目的?

你的代码可以这样写

#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;
}

最新更新