http://tinypic.com/r/1pcky1/9 这是关于我的练习中期问题的图片。
这是我的代码:
#include <stdio.h>
int FindProd(int memkey1, int memkey2, int cd1, int cd2);
int FindSum(int prod1, int prod2);
void main() {
int memkey1, cd1, memkey2, cd2;
int tProd, jProd, tjSum;
printf("How many memory keys did Tom buy? \n");
scanf("%d", &memkey1);
printf("How many memory keys did Jane buy? \n");
scanf("%d", &memkey2);
printf("How many CDs did Tom and Jane buy? (In such order) \n");
scanf("%d %d", &cd1, &cd2);
FindProd(memkey1, memkey2, cd1, cd2);
FindSum(tProd, jProd);
printf("Tom spent:\t %d \n", tProd);
printf("Jane spent:\t %d \n", jProd);
printf("Together they spent:\t %d \n", tjSum);
}
int FindProd(int memkey1, int memkey2, int cd1, int cd2)
{
int prod1 = (memkey1 * 20) + (cd1 * 10);
int prod2 = (memkey2 * 20) + (cd2 * 10);
}
int FindSum(int prod1, int prod2)
{
int prodSum = prod1 + prod2;
return prodSum;
}
据说汤姆花了50,简花了8,而他们共花了58。输入在这里完全无关紧要。我明白,为了提高效率,我的程序函数FindProd可能很糟糕,但是这里有什么?
答案 0 :(得分:0)
好的,我终于明白了。 这是我的新计划:
#include <stdio.h>
int FindProd(int memkey, int cd);
int FindSum(int prod1, int prod2);
void main() {
int memkey1, cd1, memkey2, cd2;
int tProd, jProd, tjSum;
printf("How many memory keys did Tom buy? \n");
scanf("%d", &memkey1);
printf("How many memory keys did Jane buy? \n");
scanf("%d", &memkey2);
printf("How many CDs did Tom and Jane buy? (In such order) \n");
scanf("%d %d", &cd1, &cd2);
printf("Tom spent:\t %d \n", FindProd(memkey1, cd1));
printf("Jane spent:\t %d \n", FindProd(memkey2, cd2));
tProd = FindProd(memkey1, cd1);
jProd = FindProd(memkey2, cd2);
FindSum(tProd, jProd);
printf("Together they spent:\t %d \n", FindSum(tProd, jProd));
}
int FindProd(int memkey, int cd)
{
int prod = (memkey * 20) + (cd * 10);
return prod;
}
int FindSum(int prod1, int prod2)
{
int prodSum = prod1 + prod2;
return prodSum;
}