输出中的错误没有打印出来的选择 [英] error in output not printing whats in choice
本文介绍了输出中的错误没有打印出来的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include < ; iostream.h >
#include < stdio。 h >
#include < conio.h >
#include < stdlib.h >
void SAVINGS();
int main(){
clrscr();
SAVINGS();
getch();
return 0 ;
}
void SAVINGS(){
int W,D,B,NB;
char ch;
printf( 输入账户余额:\t \ n);
scanf( %d,& B);
printf( \ n\ n);
printf( [1] Withdraw [2] Deposit\t\ n );
scanf( %s,ch);
if (ch = 1 ){
printf(< span class =code-string> \ n \ n);
printf( 为提款输入负值:\ t \ n) ;
scanf( %d,& W);
NB = B + W;
printf( \ n\ n);
printf( 您的新帐户余额为:%d \\\\ n ,NB);
if (NB< 0){
printf( 资金不足!\ n);
}
}
其他 如果(ch = 2 ){
printf( \\ \
\\\
跨度>);
printf( 输入存款的正值:\ t \ n);
scanf( %d,& D);
NB = B + D;
printf( \ n\ n);
printf( 您的新帐户余额为:%d \ t,NB) ;
}
}
解决方案
正如 phil.o 已经指出的那样,相等的C比较运算符是==
(=
是赋值运算符)。请参阅 C比较运算符/关系运算符 [ ^ ]。
hahahah i know i always ask. When you click 2nd choice(deposit) instead of showing "enter positive value" it shows "enter negative value"
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void SAVINGS();
int main(){
clrscr();
SAVINGS();
getch();
return 0;
}
void SAVINGS(){
int W,D,B,NB;
char ch;
printf("Enter Account Balance: \t \n");
scanf("%d",&B);
printf("\n\n");
printf("[1] Withdraw [2] Deposit\t\n");
scanf("%s",ch);
if (ch=1){
printf("\n\n");
printf("Enter a negative value for withdrawal:\t\n");
scanf("%d",&W);
NB=B+W;
printf("\n\n");
printf("Your new account balance is: %d\t\n",NB);
if(NB<0){
printf("Insufficient Fund!\n");
}
}
else if(ch=2){
printf("\n\n");
printf("Enter positive value for deposit: \t\n");
scanf("%d",&D);
NB=B+D;
printf("\n\n");
printf("Your new account balance is: %d\t",NB);
}
}
解决方案
As phil.o already pointed out, the C comparison operator for equality is==
(=
is the assignment operator). See C Comparison operators/relational operators[^].
这篇关于输出中的错误没有打印出来的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文