函数和变量"chicken or the egg"方案

function and variable "chicken or the egg" scenario

本文关键字:the egg 方案 or chicken 变量 函数      更新时间:2023-10-16

我正在制作一个简单的程序在c++中运行为我做ffmpeg,但我有需要在"main"中定义的某些变量的问题,但该函数需要在main之上准备使用。我能做什么?

#include <iostream>
#include <cstdlib>
using namespace std;
int convert()
{
    int operation;
    switch(operation){
        case '1':
        case '2':
        case '3':
        case '4':
            ;
    }
    return 0;
}
int main()
{
    std::string formatIn;
    std::string FormatOut;
    std::string confirm;
    cout << "select format that file is currently in: mp3, gp3, mp4, flv" << endl;
    cin >> formatIn;
    cout << "original format = " << formatIn << endl;
    cout << "choose your target format: mp3, gp3, mp4, flv" << endl;
    cin >> FormatOut;
    cout << "selected format = " << FormatOut << endl;
    cout << "proceed? ";
    cin >> confirm;
    if(confirm == "yes"){
    cout << "proceeding with operation:" << endl;
    convert();
    }
    else{
            if(confirm == "no"){
            cout << "canceling,,," << endl;
            }
    }
}

给函数一个参数:

int convert(int operation)
{
    switch(operation){

然后在main中传递一个参数:

int operation = ....
int c = convert(operation);