Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> #include <stdlib.h> #include <string.h> int menu(); void addi

ID: 3628060 • Letter: #

Question

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int menu();
void addition();
void subtraction();
void multiplication();
void division();
void adddecimals();
void subdecimals();
void muldecimals();
void divdecimals();

int main(int argc, char * argv[])
{
int choice, sub=1;
do
{
choice = menu();
if (choice == 1)
addition();
else if (choice == 2)
subtraction();
else if (choice == 3)
multiplication();
else if (choice == 4)
division();
else if (choice == 5)
adddecimals();
else if(choice==6)
subdecimals();
else if(choice==7)
muldecimals();
else if(choice==8)
divdecimals();
else if (choice == 9)
printf("Good bye! ");
}while (choice != 9);
system("PAUSE");
return 0;
}
int menu()
{
int choice;
while (choice < 1 || choice >6)
{
printf("1. Do addition problems. ");
printf("2. Do subtraction problems. ");
printf("3. Do multiplication problems. ");
printf("4. Do division problems. ");
printf("5. Addition of decimals. ");
printf("6. Subtraction of decimals. ");
printf("7. Multiplication of decimals. ");
printf("8. Division of decimals. ");

printf("Your choice --> ");
scanf("%i", &choice);
}
return choice;
}
void addition()
{
int numProblems;
int numNumbers;
int i, y;
int sum=0;
int guess;
printf("You chose addition. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to add?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
sum = sum + myArray[y];
printf("%i + ", myArray[y]);
}
printf("= ");
scanf("%i", &guess);
if (guess == sum)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void subtraction()
{
int numProblems;
int numNumbers;
int i, y,z;
int difference;
int difference1;
int guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to subtract?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
}
difference1 = myArray[0];
printf("%i - ", difference1);
for (z = 1; z < numNumbers; z++)
{
difference = difference1 - myArray[z];
printf("%i - ", myArray[z]);
}
printf("= ");
scanf("%i", &guess);
if (guess == difference)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void multiplication()
{
int numProblems;
int numNumbers;
int i, y;
int product =1;
int guess;
printf("You chose multiplication. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to multiply?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
product = product * myArray[y];
printf("%i x ", myArray[y]);
}
printf("= ");
scanf("%i", &guess);
if (guess == product)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void division()
{
int numProblems;
int numNumbers;
int i, y,z;
double quotient;
double quotient1;
double guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to divide?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
}
quotient1 = myArray[0];
printf("%.0lf / ", quotient1);
for (z = 1; z < numNumbers; z++)
{
quotient = quotient1 / myArray[z];
printf("%.0lf / ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if (guess == quotient)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void adddecimals()
{
srand(time());
int numProblems;
int numNumbers;
int i, y;
double sum=0.0;
double guess;
printf("You chose addition of decimals. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to add?: ");
scanf("%i", &numNumbers);
double myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (rand()%100+0.0);
if((myArray[y]%2)==0)
myArray[y]=myArray[y]*1.3;
else if((myArray[y]%2)==1)
myArray[y]=myArray[y]*1.5;
sum = sum + myArray[y];
printf("%.2lf + ", myArray[y]);
}
printf("= ");
scanf("%lf", &guess);
if (guess == sum)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void subdecimals()
{
int numProblems;
int numNumbers;
int i, y,z;
double difference;
double difference1;
double guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to subtract?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (double)(rand()%100);
}
difference1 = myArray[0];
printf("%lf - ", difference1);
for (z = 1; z < numNumbers; z++)
{
difference = difference1 - myArray[z];
printf("%lf - ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if (guess == difference)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void muldecimals()
{
int numProblems;
int numNumbers;
int i, y;
double product =1;
double guess;
printf("You chose multiplication. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to multiply?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (double)(rand()%100);
product = product * myArray[y];
printf("%lf x ", myArray[y]);
}
printf("= ");
scanf("%lf", &guess);
if (guess == product)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void divdecimals()
{
int numProblems;
int numNumbers;
int i, y,z;
double quotient;
double quotient1;
double guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to divide?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (double)(rand()%100);
}
quotient1 = myArray[0];
printf("%.01f / ", quotient1);
for (z = 1; z < numNumbers; z++)
{
quotient = quotient1 / myArray[z];
printf("%.0lf / ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if (guess == quotient)
printf("Correct. ");
else
printf("Incorrect. ");
}
}

Explanation / Answer

please rate - thanks

got the decimals working, and fixed some other things. I think I flagged all the changes with a //////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>          //////////////
int menu();
void addition();
void subtraction();
void multiplication();
void division();
void adddecimals();
void subdecimals();
void muldecimals();
void divdecimals();

int main(int argc, char * argv[])
{srand(time(0));            ///////////////
int choice, sub=1;
do
{
choice = menu();
if (choice == 1)
addition();
else if (choice == 2)
subtraction();
else if (choice == 3)
multiplication();
else if (choice == 4)
division();
else if (choice == 5)
adddecimals();
else if(choice==6)
subdecimals();
else if(choice==7)
muldecimals();
else if(choice==8)
divdecimals();
else if (choice == 9)
printf("Good bye! ");
}while (choice != 9);
system("PAUSE");
return 0;
}
int menu()
{
int choice;
while (choice < 1 || choice >8)
{
printf("1. Do addition problems. ");
printf("2. Do subtraction problems. ");
printf("3. Do multiplication problems. ");
printf("4. Do division problems. ");
printf("5. Addition of decimals. ");
printf("6. Subtraction of decimals. ");
printf("7. Multiplication of decimals. ");
printf("8. Division of decimals. ");

printf("Your choice --> ");
scanf("%i", &choice);
}
return choice;
}
void addition()
{
int numProblems;
int numNumbers;
int i, y;
int sum=0;
int guess;
printf("You chose addition. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to add?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{sum=0;                          ///////////////
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
sum = sum + myArray[y];
printf("%i + ", myArray[y]);
}
printf("= ");
scanf("%i", &guess);
if (guess == sum)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void subtraction()
{
int numProblems;
int numNumbers;
int i, y,z;
int difference;
int difference1;
int guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to subtract?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
}
difference = myArray[0];
printf("%i - ", difference);    /////////////////////
for (z = 1; z < numNumbers; z++)
{
difference = difference - myArray[z];
printf("%i - ", myArray[z]);
}
printf("= ");
scanf("%i", &guess);
if (guess == difference)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void multiplication()
{
int numProblems;
int numNumbers;
int i, y;
int product =1;
int guess;
printf("You chose multiplication. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to multiply?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{product =1;                      //////////////////////
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
product = product * myArray[y];
printf("%i x ", myArray[y]);
}
printf("= ");
scanf("%i", &guess);
if (guess == product)
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void division()
{
int numProblems;
int numNumbers;
int i, y,z;
double quotient;
double quotient1;
double guess;
printf("You chose division. ");            ///////////
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to divide?: ");
scanf("%i", &numNumbers);
int myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = rand()%100;
}
quotient = myArray[0];               ///////////////
printf("%d / ", myArray[0]);           //////////
for (z = 1; z < numNumbers; z++)
{
quotient = quotient / myArray[z];        ///////////////////////////
printf("%d / ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if ((floor)(guess*100) == (floor)(quotient*100))     //////////
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void adddecimals()
{

int numProblems;
int numNumbers;
int i, y;
double sum=0.0;
double guess;
printf("You chose addition of decimals. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to add?: ");
scanf("%i", &numNumbers);
double myArray[numNumbers];
for (i = 0; i < numProblems; i++)
{sum=0.0;                       ////////////////////////
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (rand()%1000)/100.;    ////////////////////
sum = sum + myArray[y];
printf("%.2lf + ", myArray[y]);
}
printf("= ");
scanf("%lf", &guess);
if ((floor)(guess*100) == (floor)(sum*100))     //////////
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void subdecimals()
{
int numProblems;
int numNumbers;
int i, y,z;
double difference;
double difference1;
double guess;
printf("You chose subtraction. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to subtract?: ");
scanf("%i", &numNumbers);
double myArray[numNumbers];              /////////////////////
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (rand()%1000)/100.;           //////////////////
}
difference = myArray[0];                     //////////////////////////
printf("%lf - ", myArray[0]);
for (z = 1; z < numNumbers; z++)
{
difference = difference - myArray[z];       //////////////////////////////
printf("%lf - ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if ((floor)(guess*100) == (floor)(difference*100))    //////////////////////////
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void muldecimals()
{
int numProblems;
int numNumbers;
int i, y;
double product =1;
double guess;
printf("You chose multiplication. ");
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to multiply?: ");
scanf("%i", &numNumbers);
double myArray[numNumbers];        /////////////////
for (i = 0; i < numProblems; i++)
{product =1;        ///////////////////////////
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (rand()%1000)/100.;    /////////////////////
product = product * myArray[y];
printf("%lf x ", myArray[y]);
}
printf("= ");
scanf("%lf", &guess);
if ((floor)(guess*100) == (floor)(product*100)) ///////////////
printf("Correct. ");
else
printf("Incorrect. ");
}
}
void divdecimals()
{
int numProblems;
int numNumbers;
int i, y,z;
double quotient;
double quotient1;
double guess;
printf("You chose division. ");                ///////////////
printf("How many problems would you like to do?: ");
scanf("%i", &numProblems);
printf("How many numbers would you like to divide?: ");
scanf("%i", &numNumbers);
double myArray[numNumbers];            //////////////
for (i = 0; i < numProblems; i++)
{
for (y = 0; y < numNumbers; y++)
{
myArray[y] = (rand()%1000)/100.;   /////////////////////
}
quotient = myArray[0];                            ////////////////////////
printf("%.2f / ", myArray[0]);          //////////////////
for (z = 1; z < numNumbers; z++)
{
quotient = quotient / myArray[z];                ////////////////////////
printf("%.2f / ", myArray[z]);
}
printf("= ");
scanf("%lf", &guess);
if ((floor)(guess*100) == (floor)(quotient*100)) ////////////
printf("Correct. ");
else
printf("Incorrect. ");
}
}