Function 线程1:断点3.1?
为什么我的程序在那一点停止?我想创建一个函数来打印复利后的余额,但由于某些原因,它没有打印。。。这就是我所拥有的:Function 线程1:断点3.1?,function,debugging,pass-by-reference,breakpoints,Function,Debugging,Pass By Reference,Breakpoints,为什么我的程序在那一点停止?我想创建一个函数来打印复利后的余额,但由于某些原因,它没有打印。。。这就是我所拥有的: #include <stdio.h> #include <stdlib.h> #include <math.h> int printBalance(double initial, double interest, double years); int main() { double initial, interest, i, years
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int printBalance(double initial, double interest, double years);
int main() {
double initial, interest, i, years;
printf("Enter initial deposit: ");
scanf("%lf", &initial);
printf("Enter percent interest rate: ");
scanf("%lf", &interest);
printf("Enter the number of years: ");
scanf("%lf", &years);
for (i = 0; i < years; i++) {
printBalance(initial, interest, i);
}
}
int printBalance(double initial, double interest, double years) {
double balance;
balance = initial * (pow((1 + interest/100), years));
printf("%lf", balance);
return 0;
}
#包括
#包括
#包括
int打印余额(双首付、双利息、双年);
int main(){
双首字母,利息,i,年;
printf(“输入初始存款:”);
scanf(“%lf”和首字母);
printf(“输入利率百分比:”);
scanf(“%lf”和利息);
printf(“输入年份:”);
scanf(“%lf”、&years);
对于(i=0;i<年;i++){
打印余额(初始、利息、i);
}
}
整数打印余额(双倍首付、双倍利息、双年度){
双平衡;
余额=初始*(pow((1+利息/100),年);
printf(“%lf”,余额);
返回0;
}
考虑以下几点
/* This program calculates the balance after compound interest. The user is
* prompted to enter an initial amount, percent interest, and a number of
* years. This program outputs the year number, principal amount at the
* start of that year, the amount compounded, and the balance after the
* compounding. */
#include <stdio.h> //includes input/output library
#include <stdlib.h> //includes general purpose functions
#include <math.h> //includes math functions
#include <string.h> //includes string operations
void printBalance(); //enables printBalance function
int main() { //main function
while (1) { //infinite loop--never leave main
char x[1]; //initializes 1-character string x
do { //do-while loop: do 'this' while
//'these conditions apply;
printBalance(); //invokes printBalance function--
call by reference
printf("\nTry again? Y or N? ");
scanf("%s", x); //prompt user to input character
into x
}
while (strcmp(x, "Y") == 0); //if the difference of the ASCII
values of x and "Y" is 0,
reiterate the loop
return 0;
}
}
void printBalance() { //create printBalance function
int i; //initialize integer i and the
following doubles
double initial, interest, years, temp, ci, cii, balance;
printf("Enter initial deposit: ");
scanf("%lf", &initial); //prompt user to input initial
deposit
printf("Enter percent interest rate: ");
scanf("%lf", &interest); //prompt user to input percent
interest
printf("Enter the number of years: ");
scanf("%lf", &years); //prompt user to imput number of
years
printf("\nYear\t\tInitial\t\tCompound Interest\t\tBalance\n");
printf("----\t\t-------\t\t-----------------\t\t-------\n");
temp = initial; //create temporary variable as a
mask
for (i = 1; i <= years + 1; i++) { //print compounded value for each
year iterated
ci = initial * (pow((1 + interest/100), years)-1);
balance = initial * pow((1 + interest/100), i);
cii = balance - temp; //another mask variable
printf("%d\t\t\t%.2lf\t\t%.2lf\t\t\t\t\t%.2lf\n", i, temp, cii,
balance);
temp = balance;
}
}
/*此程序计算复利后的余额。用户是
*提示输入初始金额、利息百分比和
*年。该程序输出年度编号、当前的本金金额
*当年年初,复利金额,以及复利后的余额
*复配*/
#include//includes输入/输出库
#include//includes通用函数
#include//includes数学函数
#include//includes字符串操作
作废打印余额()//启用打印平衡功能
int main(){//main函数
while(1){//无限循环——永远不要离开main
char x[1];//初始化1个字符的字符串x
do{//do while循环:在
//"这些条件适用,;
printBalance();//调用printBalance函数--
参考电话
printf(“\N再次尝试?Y还是N?”);
scanf(“%s”,x);//提示用户输入字符
进入x
}
while(strcmp(x,Y”)==0);//如果
x和“Y”的值为0,
重复循环
返回0;
}
}
void printBalance(){//创建printBalance函数
int i;//初始化整数i和
紧随其后的双打
双首字母、利息、年份、临时工、ci、cii、余额;
printf(“输入初始存款:”);
scanf(“%lf”,&initial);//提示用户输入首字母
押金
printf(“输入利率百分比:”);
scanf(“%lf”,&interest);//提示用户输入百分比
兴趣
printf(“输入年份:”);
scanf(“%lf”,&years);//提示用户输入
年
printf(“\nYear\t\tinial\t\t复合权益\t\t余额\n”);
printf(“-----\t\t------\t\t------\t\t------\n”);
temp=initial;//创建临时变量作为
面具
对于(i=1;i