新学生使用字符串和函数 [英] New student working with strings and functions

查看:96
本文介绍了新学生使用字符串和函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要询问用户3个职位,然后创建一个程序,预测的工作,用户将有...像一个财富出纳员。此分配的说明是为输入的作业的摘要创建一个函数,然后显示算命师。我很困惑如何发送字符串日期到函数,然后再次调用它。我不断收到读取太多参数发送到函数的错误,以及在第89行之前<<<<>之前的预期主表达式

http://www.screencast.com/t/wiHzraAI

  using namespace std; 

void splash();
void welcome();
void summary(string,string,string,string);

int main(int argc,char * argv [])
{
string career1,career2,career3;
int num1;

splash();
welcome();

system(CLS);

unsigned seed = time(0);
srand );
num1 = 1 + rand()%4;

cout <<< down12;
cout< ;
getline(cin,career1);
system(CLS);

cout<<< down12;
cout< ;<Enter Career 2:;
getline(cin,career2);
system(CLS);

cout< down12;
cout<< over3< Enter Career 3:;
getline(cin,career3);
system(CLS);

cout<< down10;

if(num1 == 1)
summary(career1,career2,career3,career1);
else if(num1 == 2)
summary(career1,career2,career3,career2);
else if(num1 == 3)
summary(career1,career2,career3,career3);
else
summary(career1,career2,career3,none of these jobs ...);

cout<< down10;
return EXIT_SUCCESS;

}

void summary(string,string,string,string)
{
cout< down5;
cout<< over3< 你输入的工作是:< endl;
cout<< over3< __________________________< endl;
cout<< over3< 1.< string<< endl;
cout<< over3< 2.< string<< endl;
cout<< over3< 3.< string<< endl;
cout<< over3< 你的工作将是< string<< endl;
}


解决方案

的函数定义如下:

  void summary(string string1,string string2,string string3,string string4); 

此外,您还需要确保为输出使用适当的变量名。



希望有所帮助!


I need to ask the user for 3 job titles and then create a program that will "predict" the job the user will have...like a Fortune Teller. The instructions for this assignment was to create a function for the summary of the jobs entered and then display the fortune teller. I am confused as to how to send string date to the function and then call it again. I keep getting errors that read too many parameters sent to function and "expected primary-expression before << on line 89

http://www.screencast.com/t/wiHzraAI

    using namespace std;

void splash();
void welcome();
void summary(string,string,string,string);

int main(int argc, char *argv[]) 
{
    string career1, career2, career3;
    int num1;

    splash ();
    welcome ();

    system("CLS");

    unsigned seed = time(0);
    srand(seed);
    num1 = 1 +rand() % 4;   

    cout << down12;
    cout << over3 << "Enter Career 1: ";
    getline(cin, career1);
    system("CLS");

    cout << down12;
    cout << over3 << "Enter Career 2: ";
    getline(cin, career2);
    system("CLS");

    cout << down12;
    cout << over3 << "Enter Career 3: ";
    getline(cin, career3);
    system("CLS");

    cout << down10;

    if (num1 == 1)
        summary(career1,career2,career3,career1);
    else if (num1 == 2)
        summary(career1,career2,career3,career2);
    else if (num1 ==3)
        summary(career1,career2,career3,career3);
    else 
        summary(career1,career2,career3,"none of these jobs...");

    cout << down10;
    return EXIT_SUCCESS;

}

void summary(string,string,string,string)
{
    cout << down5;
    cout << over3 << "The jobs you entered were:" << endl;
    cout << over3 << "__________________________" << endl;
    cout << over3 << "1. " << string << endl;
    cout << over3 << "2. " << string << endl;
    cout << over3 << "3. " << string << endl;
    cout << over3 << "Your job will be " << string <<endl;  
}

解决方案

I would just adjust the parameters of the function definition like so:

void summary(string string1, string string2, string string3, string string4);

Also, you'll want to be sure that you're using the appropriate variable names for your output.

Hope that helps!

这篇关于新学生使用字符串和函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆