c语言打印void *,C语言简介:添加和打印

我正在试着制作一个基本的计算器,它可以执行各种算术功能,从添加开始!现在我已经掌握了它的基本逻辑,但我不确定如何接受两个输入并将其打印出来!C语言简介:添加和打印

#include

int main()

{

char mychar;

int a;

int op1;

int op2;

printf("Welcome to Andrew Hu's calculator program!\n"); //Greeting

while(1)

{ printf("Enter a mathematical operation to perform:\n");

scanf("%c", &mychar);

if(mychar == '+') //Valid Operators

a = 1;

else

a = 0;

if(a == 0) //Operator Checker, error if invalid

printf("\nError, not a valid operator\n");

else if(a == 1){

printf("%c\n", &mychar),

printf("Enter OP1:\n"),

/* not sure what to put here to echo the character as a decimal*/

printf("Enter OP2:\n"),

/* not sure what to put here to echo the character as a decimal either*/

printf("Result of %d %c %d = %d\n", op1, mychar, op2, (op1 + op2))

/* this last line I'm not too sure of. I'm trying to print out the expression

which is op1 + op2 = the sum of both. */

;

}

}

+0

你首先要做的是找出不同的输入方法。最常用的(初学者)是'scanf'。然后,您必须阅读['scanf'手册](http://pubs.opengroup.org/onlinepubs/009695399/functions/scanf.html)。当您了解如何使用scanf时,开始编码_only_。 –

+1

@Andrew Hu - 不要忘记接受答案,已经解决了你的问题/问题:) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值