I'm taking an intro course to programmign in C. My current assignment is pretty straight forward. I have to read two sets of integers compare them and find the lesser value. In other words, it's a vacation cost calculator designed to find which hypothetical trip is cheaper.
I'm still a little shakey with functions and global vs local variables so bear with me. I've met with a problem: the two trips I'm comparing are Australia and Europe. I have to use functions to calculate the costs and display the output values.
I thought I'd declare a global string to represent the locations. At first its value would be "Europe" and when it returns from the function, I'd set it to "Australia" and display its output.
I get an error, and I don't know how to resolve it. the string is named "dest" and I'm trying to use the command: "dest="Australia". Any help or pointers are appreciated.
#include <stdio.h>
char dest[9]="Europe";
void calculateExpenses(); /* the function declaration */
void PrintResults();
main() {
int etik, eexp, ehot, efood, atik, aexp, ahot, afood;
printf("Enter the ticket, traveling, hotel and dining costs separated by a space for Europe: \n"
scanf("%d %d %d %d", &etik, &eexp, &ehot, &efood);
printf("Enter the ticket, traveling, hotel and dining costs separated by a space for Australia: \n"
scanf("%d %d %d %d", &atik, &aexp, &ahot, &afood);
calculateExpenses(etik, eexp, ehot, efood); /* the function call */
calculateExpenses(atik, aexp, ahot, afood); /* the function call */
return 0; /* exit main function */
}
void calculateExpenses(int w, int x, int y, int z) { /* the function definition */
int travel = (int) (w + x); /* coersion */
int board = (int) (y + z);
int total = (travel + board);
PrintResults(travel, board, total);
}
void PrintResults(int t, int b, int tot){ /* the function definition */
printf("Travelling Expenses for %s are %d\n", dest, t);
printf("Boarding Expenses for %s are %d\n", dest, b);
printf("The total expenses for %s are %d\n", dest, tot);
}
I'm still a little shakey with functions and global vs local variables so bear with me. I've met with a problem: the two trips I'm comparing are Australia and Europe. I have to use functions to calculate the costs and display the output values.
I thought I'd declare a global string to represent the locations. At first its value would be "Europe" and when it returns from the function, I'd set it to "Australia" and display its output.
I get an error, and I don't know how to resolve it. the string is named "dest" and I'm trying to use the command: "dest="Australia". Any help or pointers are appreciated.
#include <stdio.h>
char dest[9]="Europe";
void calculateExpenses(); /* the function declaration */
void PrintResults();
main() {
int etik, eexp, ehot, efood, atik, aexp, ahot, afood;
printf("Enter the ticket, traveling, hotel and dining costs separated by a space for Europe: \n"
scanf("%d %d %d %d", &etik, &eexp, &ehot, &efood);
printf("Enter the ticket, traveling, hotel and dining costs separated by a space for Australia: \n"
scanf("%d %d %d %d", &atik, &aexp, &ahot, &afood);
calculateExpenses(etik, eexp, ehot, efood); /* the function call */
calculateExpenses(atik, aexp, ahot, afood); /* the function call */
return 0; /* exit main function */
}
void calculateExpenses(int w, int x, int y, int z) { /* the function definition */
int travel = (int) (w + x); /* coersion */
int board = (int) (y + z);
int total = (travel + board);
PrintResults(travel, board, total);
}
void PrintResults(int t, int b, int tot){ /* the function definition */
printf("Travelling Expenses for %s are %d\n", dest, t);
printf("Boarding Expenses for %s are %d\n", dest, b);
printf("The total expenses for %s are %d\n", dest, tot);
}