从多项选择中只获得很少的价值

Get only few value from multiple choice

本文关键字:选择      更新时间:2023-10-16

我为用户提供了多种输入选择。我希望用户选择两个选项,并且我想将选项存储在num1num2中:

#include<iostream>
using namespace std;
int main()
{
    cout<<"This programme will calculate the profit and loss "<<endl;
    int num1,num2;
    cout<<"What are the given terms "<<'n'
        <<"Please enter any two known terms to find the other remaining unknown terms"<<endl;
    cout<<" Cost price:-"<<endl;
    cout<<" selling price"<<endl;
    cout<<" profit "<<endl;
    cout<<"profit percentage "<<endl;
    cout<<" loss "<<endl;
    cout<<" losspercentage "<<endl;
    // i want to store any of the two values in num1 and num2;
}

要选择两个选项num1和num2,现在你写:

    cin>>num1;
    cin>>num2;

您可以通过使用 fstream 文件并键入将其存储在文件中

    ofstream file;
     file.open ("report.txt", ios::app);