嗨我有一個程序,它是一個計算器程序,用於計算兩個整數的和,差或乘積。程序首先要求計算的類型(1 =總和,2 =差值,3 =乘積)。計算完成後,結果顯示在屏幕上,程序返回以提示下一次計算。C編程程序在未詢問時需要輸入
#include <stdio.h>
int addition(int a , int b);
int subtraction(int a, int b);
int multiplication(int a , int b);
int main()
{
int choicea, choiceb, cal;
do{
printf("1: sum of two numbers\n2: difference of two numbers\n3: product of two numbers\n");
printf("<0: terminate the program\n");
printf("Select calculation:");
scanf("%d", &cal);
printf("Enter the first number:");
scanf("%d", &choicea);
printf("Enter the second number:");
scanf("%d", &choiceb);
if(choicea < 0 || choiceb < 0) {
printf("Terminating the program...");
}
else if(cal == 1) {
addition(choicea , choiceb);
}
else if(cal == 2) {
subtraction(choicea, choiceb);
}
else if(cal == 3) {
multiplication(choicea, choiceb);
}
else {
printf("You entered an invalid number.\n\n");
}
}while(cal>0);
return 0;
}
int addition(int a , int b){
int cal = a + b ;
return printf("%d + %d = %d\n", a , b , cal);
}
int subtraction(int a, int b){
int cal = a - b ;
return printf("%d - %d = %d\n", a , b , cal);
}
int multiplication(int a , int b){
int cal = a * b ;
return printf("%d * %d = %d\n", a , b , cal);
}
編譯器由教程網站給出,所以它不在我的電腦上,我得到的錯誤是這樣的。
'return printf(「%d +%d =%d \ n」,a,b,cal);'''''''printf返回寫入的總字符數。希望這是你想要做的。 – sjsam
您的輸出與本網站期望的內容不符。檢查程序規格以確保你做的是正確的事情。如果結果是負面的,我懷疑你應該放棄。 – dbush
它在這裏工作得很好,而且就我所見,它似乎可以在您的教程網站上正常工作。是什麼讓你覺得它不起作用?這是什麼教程網站? –