初学C:错误:控制到达非void函数的结束? [英] Beginner C: error: control reaches end of non-void function?

查看:1515
本文介绍了初学C:错误:控制到达非void函数的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个贪心算法,我得到这个错误:

I'm trying to make a greedy algorithm and I get this error:

greedy2.c:27:1: error: control reaches end of non-void function
      [-Werror,-Wreturn-type]
}
^
1 error generated.

本code:

int man(int argc, char* argv[])
{

  float amount;
  do
    {
      printf("Input dollar amount owed:\n");
      amount = GetFloat();
    }
  while (amount <= 0);    
  int coins = 0;
  while (amount >= 0.25);
  {
    amount = amount - 0.25;
    coins++;
  }
  printf("Number of coins to use: %d\n", coins);

}

什么是错我的花括号,如何解决呢?

What is wrong with my curly braces, and how do I fix it?

推荐答案

要简短地回答你的问题,添加:

To answer your question briefly, add:

return 0;

结束前的main()

您也可以在名称中一个错字。这也可能是,而不是

You also have a typo in the name. It's probably main, not man.

要给你一个较长的答案,你定义的为返回一个整数( INT ),但没有收益语句在它的结束,因此它不返回任何东西。

To give you a longer answer, you defined main as returning an integer (int) but have no return statement at the end of it, so it doesn't return anything.

这篇关于初学C:错误:控制到达非void函数的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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