gpt4 book ai didi

c++ - 函数在控制台中运行两次

转载 作者:太空宇宙 更新时间:2023-11-04 15:01:45 24 4
gpt4 key购买 nike

<分区>

基本上,每当我在控制台中运行这个程序来测试它时,我的 Menu() 函数就会被调用,当我提供输入时,它会再次打印整个 Menu() 函数。请帮我解决这个问题。附:这是不完整的。

#include <iostream>
#include <windows.h>

using namespace std;

int Menu();

int main()
{

float currMoney = 0;
float giveMoney = 0;

float coke = 8.50;
float fantaG = 9;
float fantaO = 9;
float creamS = 7;


Menu();

int Choice = Menu();
system("cls");
if(Choice == 1)
{
cout<< "Insert R"<< coke << endl;

int pay = 0;
cin>> pay;

float returnA = pay - coke;

if(returnA < 0)
{
returnA = -returnA;
cout<< "you still owe R"<< returnA << "0" << endl;
}
}


}


int Menu()
{
cout<< "[Drink machine v1.0]\n\n"<< endl;

cout<< "[1]Coke -- R8,50"<< endl;
cout<< "[2]Fanta grape -- R9,00" <<endl;
cout<< "[3]Fanta orange -- R9,00"<< endl;
cout<< "[4]Cream Soda -- R7,00"<< endl;

int Choice = 0;
cin>> Choice;

return Choice;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com