#include %26lt;stdio.h%26gt;
int funcadd(num1, num2) {
int result;
result = num1 + num2;
}
int funcsub(num1, num2) {
int result;
result = num1 - num2;
}
int funcmult(num1, num2) {
int result;
result = num1 * num2;
}
main() {
int result, var1, var2;
char unit;
printf("type first value\n");
scanf("%d",%26amp;var1);
printf("type a to add s to subtract m to m multiply:\n");
scanf("%c", %26amp;unit);
printf("type second value\n");
scanf("%d",%26amp;var2);
if (unit = 'a') {
result = funcadd(var1, var2);
printf("the answer is %d\n", result);
}
if (unit = 's') {
result = funcsub(var1, var2);
printf("the answer is %d\n", result);
}
if (unit = 'm') {
result = funcmult(var1, var2);
printf("the answer is %d\n", result);
}
printf("%c", unit);
}
PRODUCES
type first value
5
type a to add s to subtract m to multiply
type second value
6
the answer is 11
the answer is -1
the answer is 30
m
Problem with a program in c using functions ,ive written the program in notepad.?
I guess this is the program you are looking for! Try to compile and run. Hope it will help. ^^
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
int funcadd(int num1, int num2) {
int res = num1 + num2;
return res;
}
int funcsub(int num1, int num2) {
int res = num1 - num2;
return res;
}
int funcmult(int num1, int num2) {
int res = num1 * num2;
return res;
}
void main() {
int result1, result2, result3, var1, var2;
char unit;
clrscr();
do{
printf("type first value\n");
scanf("%d",%26amp;var1);
printf("type a to add s to subtract m to multiply\n");
unit=getch();
unit=tolower(unit);
printf("type second value\n");
scanf("%d",%26amp;var2);
switch(unit)
{
case 'a' :
{
result1 = funcadd(var1, var2);
printf("the answer is %d\n", result1);
printf("%c",unit);
}break;
case 's' :
{
result1 = funcadd(var1, var2);
printf("the answer is %d\n", result1);
result2 = funcsub(var1, var2);
printf("the answer is %d\n", result2);
printf("%c",unit);
}break;
case 'm' :
{
result1 = funcadd(var1, var2);
printf("the answer is %d\n", result1);
result2 = funcsub(var1, var2);
printf("the answer is %d\n", result2);
result3 = funcmult(var1, var2);
printf("the answer is %d\n", result3);
printf("%c",unit);
}break;
}
}while(unit=='x');
getch();
}
~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o...
yeah! you're right! if I use getchar(); function my created program will be lessen.. thanks for the idea. hope you mark my answer as the best because it complied with the requirements you need. thanks. ^^
Reply:And what is the problem?
Reply:if (unit == 's')
(and the same for the others)
INSTEAD OF ADDITIONAL DETAILS:
PLEASE DO WHAT I'VE WRITTEN, AND DON'T LOSE TIME. IT'S THE SOLUTION!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment