0
我正在改變計數器程序,我卡住了,我在這裏和其他2個編碼論壇,谷歌和YouTube的,但還沒有找到答案...我的程序很爛,我是全新的C/C++ ...我的TXT書還沒有在這裏,所以我正在努力閱讀每一件事,我可以得到我的手,直到它到達這裏更改計數器c程序不顯示正確的輸出
這是什麼輸出應該在控制檯窗口:
Welcome to Change Counter by Jo Mama!!
Please enter the total amount of purchase: $52.173
$52.173
Please enter amount of money tendered: $60
$60.00
Your change is: $7.83
-------------------------------------------
Twenties : 0
Tens : 0
Fives : 1
Ones : 2
Quarters : 3
Dimes : 0
Nickels : 1
Pennies : 3
-------------------------------------------
Thank you for using Change Counter!
這裏是我迄今爲止...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
// define variables here
long double numberOfTwenties = 0;
long double numberOfTens = 0;
long double numberOfFives = 0;
long double numberOfOnes = 0;
long double numberOfQuarters = 0;
long double numberOfDimes = 0;
long double numberOfNickels = 0;
long double numberOfPennies = 0;
double purchasePrice = 0;
double amountTendered = 0;
double amountOfChange = 0;
double amountOfChangeCents = 0;
// start program here
printf("Welcome to the change counter by Josh Manion!!\n\n");
printf("Please enter the total amount of purchase: $");
scanf("%d", &purchasePrice);
printf("%d\n", purchasePrice);
printf("Please enter amount of money tendered: $");
scanf("%d", &amountTendered);
printf("%d\n", amountTendered);
//do change calculations here
amountOfChange = (amountTendered - purchasePrice);
printf("Your change is: $%d\n", amountOfChange);
numberOfTwenties = amountOfChange/20;
//amountOfChange = numberOfTwenties %= amountOfChange;
numberOfTens = (amountOfChange/10);
numberOfFives = (amountOfChange/5);
numberOfOnes = (amountOfChange/1);
numberOfQuarters = (amountOfChange * 0.25);
// print change calculations here
printf("---------------------------------------------\n");
//display denominations of change here
printf("Twenties: %d\n", numberOfTwenties);
printf("Tens: %d\n", numberOfTens);
printf("Fives: %d\n", numberOfFives);
printf("Ones: %d\n", numberOfOnes);
printf("Quarters: %d\n", numberOfQuarters);
printf("Dimes: %d\n", numberOfDimes);
printf("Nickels: %d\n", numberOfNickels);
printf("Pennies: %d\n", numberOfPennies);
printf("---------------------------------------------\n");
printf("Thank you for using the Change Counter!");
getchar();
return EXIT_SUCCESS;
}
問題是我的程序不工作,它顯示提示後的變化,但不是面值的細分,我傾向於使用「%」來降低變化量,但我還沒有找到任何示例。我不知道還有什麼要說...除了我是新的,這個職位將幫助很多人...
cplusplus.com有一個不錯的表爲各種修飾:http://www.cplusplus.com/reference/cstdio/printf/ – kay 2014-10-11 02:49:24
@Kay我推薦[printf man頁面(http://linux.die.net/man/3/printf)。有時候,cplusplus.com會皺起眉頭。 – 2014-10-11 05:09:48
@remyabel,die.net格式不正確,覆蓋廣告。 – kay 2014-10-11 15:14:45