C 将用户输入从一个函数到另一个功能,并使用Main(Newbie)显示

C++ Carrying user input from one function to another and displaying it with main(newbie)

本文关键字:显示 功能 Main 另一个 Newbie 函数 输入 用户 一个      更新时间:2023-10-16

尝试使用getinput函数输入用户输入,将其传输到vaidornot函数,并显示else否则使用MAIN方法屏幕循环,但我无法。我怎样才能做到这一点 ?同样有双重变量的问题吗?:(

#include <iostream>
#include <string>
using namespace std;
void getinput(string restname, string name, double point) {
    cout << name << "please enter the name of restaurant: " << endl;
    cin >> restname;
    cout << name << "please enter the scores of" << restname << "for first level evolution" << endl;
    cin >> point;
}
void validornot(double point) {
    if (point > 5) {
        cout << "point is bigger than 5" << endl;
    }
    else {
        cout << "point is smaller than 5" << endl;
    }
}
int main() {
    string name;
    string restname;
    double point;
    cout << "Welcome to my restaurant rating programme.Please enter your name to start:" << endl;
    cin >> name;
    cout << "Welcome " << name << endl;
    getinput(restname, name, point);
    validornot(point);
    return 0;
}

您可以更改void getinput(string restname,string name, double point)

void getinput(string restname,string name, double& point)