小编use*_*534的帖子

在Objective-C Foundation命令行实用程序中使用用户输入

我正在尝试创建一个解决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 …
Run Code Online (Sandbox Code Playgroud)

xcode command-line user-input objective-c

5
推荐指数
1
解决办法
9257
查看次数

标签 统计

command-line ×1

objective-c ×1

user-input ×1

xcode ×1