#include int main() { int oranges; int students; unsigned int price = 2; // 2 dollars per apple printf("Quantity of students: "); scanf("%d", &students); printf("Quantity of oranges per student: ");...

1 answer below »
Need these questions answered about this program


#include int main() { int oranges; int students; unsigned int price = 2; // 2 dollars per apple printf("Quantity of students: "); scanf("%d", &students); printf("Quantity of oranges per student: "); scanf("%d", &oranges); // get total oranges oranges = oranges * students; // get total price price = price * oranges; // print result printf("The price for %d oranges is $%d\n", oranges, price); return 0; }
Answered Same DaySep 08, 2021

Answer To: #include int main() { int oranges; int students; unsigned int price = 2; // 2 dollars per apple...

Ramachandran answered on Sep 09 2021
169 Votes
Order-90815/oranges.c
#include
#include
#include
#include
unsigned int convert(char
* st) {
char * x;
for (x = st;* x; x++) {
if (!isdigit( * x))
return 0L;
}
return (strtoul(st, 0L, 10));
}
void checkValidUnsignedInt(char input[]) {
unsigned int x = convert(input);
char extractedInput[10];
sprintf(extractedInput, "%u", x);
if (strcmp(input, extractedInput) != 0) {
printf("please enter a valid value");
exit(1);
}
}
unsigned int multiply(unsigned int num1, unsigned int num2) {
unsigned result = num1 * num2;
if (num1 != 0 && ((result / num1) != num2)) {
printf("multiplication overflow");
exit(1);
}
return result;
}
int main() {
unsigned oranges;
unsigned students;
unsigned int price = 2; // 2 dollars per apple
printf("Quantity of students: \n");
char userInput[10];
scanf("%10s", userInput);
checkValidUnsignedInt(userInput);
students = convert(userInput);
printf("Quantity of students entered:%u\n", students);
printf("Quantity of oranges per student: \n");
scanf("%10s", userInput);
checkValidUnsignedInt(userInput);
oranges = convert(userInput);
printf("Quantity of oranges per student entered:%u\n", oranges);
// total oranges
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here