加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在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;

您的程序然后在我的机器上正常工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读