错误 "too few arguments to function call, at least argument 'format' must be specified" C 编程

Error "too few arguments to function call, at least argument 'format' must be specified" C programming

#include <cs50.h>

//declare functions

int add_two_ints(int a, int b);

int main(void)
{
    //ask the user for input
    
    printf("give an integer: ");
    int x = get_int();

    printf("give me another integer: ");
    int y = get_int();
    //call function

    int z = add_two_ints(x, y);
    

    printf("the result of %i plus %i is %i!\n", x, y, z);


}

//function
int add_two_ints(int a, int b)
{
    int sum = a + b;
    return sum;
}

当我 运行 程序出现错误时,函数调用的参数太少,至少必须指定参数格式

这是一个简单的函数,只传递了两个参数,因为我是 c 编程的新手,我试图找出我在哪里犯了错误。 函数的正确写法是什么?

作为 CS50 的一部分包含的 get_int 函数需要一个提示字符串,您没有传递该字符串。所以不是这个:

printf("give an integer: ");
int x = get_int();

你想要这个:

int x = get_int("give an integer: ");

阅读也类似y

我刚刚意识到我做错了什么 get_int 期待一个字符串所以我只是删除了 printf 语句并放入 get_int 所以现在当它运行时有效

#include <stdio.h>
#include <cs50.h>

//declare functions

int add_two_ints(int a, int b);

int main(void)
{
//ask the user for input
    
    
int x = get_int("give an integer: ");


int y = get_int("give an integer: ");

int z = add_two_ints(x, y);

printf("the result of %i plus %i is %i!\n", x, y, z);


}

int add_two_ints(int a, int b)
{
int sum = a + b;
return sum;
}