在Objective-C Foundation命令行实用程序中使用用户输入
发布时间:2020-12-14 19:22:02 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个解决Objective-C命令行中的二次公式的应用程序.到目前为止我的代码是: #import Foundation/Foundation.hint main (int argc,const char * argv[]){double a,b,c,sol1,sol2;NSLog(@"Welcome to the quadratic solver");NSLog(@"Please ent
我正在尝试创建一个解决Objective-C命令行中的二次公式的应用程序.到目前为止我的代码是:
#import <Foundation/Foundation.h> int main (int argc,const char * argv[]){ double a,b,c,sol1,sol2; NSLog(@"Welcome to the quadratic solver"); NSLog(@"Please enter the value of a"); scanf("%f",&a); NSLog(@"Please enter the value of b"); scanf("%f",&b); NSLog(@"Please enter the value of c"); scanf("%f",&c); sol1 = (-b + sqrt( (double)pow(b,2) - 4 * a *c) ) / 2 * a; sol2 = (-b - sqrt( (double)pow(b,2) - 4 * a *c) ) / 2 * a; NSLog(@"If a is: %f,b is %f,and c is %f.",a,c); NSLog(@"Solution one is: %f",sol1); NSLog(@"Solution two is: %f",sol2); } 但我的输出没有收到任何信息. 2012-01-26 17:23:53.585 test[4595:707] Welcome to the quadratic solver 2012-01-26 17:23:53.588 test[4595:707] Please enter the value of a 1 2012-01-26 17:23:56.030 test[4595:707] Please enter the value of b 3 2012-01-26 17:23:56.558 test[4595:707] Please enter the value of c -10 2012-01-26 17:23:58.670 test[4595:707] If a is: 0.000000,b is 0.000000,and c is 0.000000. 2012-01-26 17:23:58.672 test[4595:707] Solution one is: -0.000000 2012-01-26 17:23:58.672 test[4595:707] Solution two is: -0.000000 任何输入都非常感谢! 解决方法
您输入的内容不一致…您正在扫描到%f,因此您需要声明:
float a,sol2; 您的程序然后在我的机器上正常工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 关联,聚合,组合的区别及C++实现
- ruby-on-rails – Rails日期格式(匹配YYYY-MM-DD HH-MM-SS)
- c# – 使用.NET 2.0,如何FTP到服务器,获取文件和删除文件?
- Match One of Two Alternatives Based on a Condition (基于
- Benchmarksql-5.0安装
- 返回JSONArray而不是JSONObject,Jersey JAX-RS
- c# – 当Enum类型未知时返回默认枚举值
- ruby-on-rails – Rails多步模型创建
- ruby-on-rails-3 – 在paper_trail版本表中存储user_id
- c# – EF6 CodeFirst My [Key] Id列不会自动递增,因为标识列