1. Write a function to have a user enter some number of integers into an array.
ID: 3541062 • Letter: 1
Question
1. Write a function to have a user enter some number of integers into an array. The integer values must be between -100 and +100 inclusive (+100 and -100 should be accepted as valid inputs). The integer array and the size of the array are passed into the function through parameters. Do not worry about includes. This is only a function, so there is no main routine. The function should fill the array with valid inputs. For invalid input values, inform the user of the error, but do not count that as a valid input.
2. .Write a function that takes inputs of quarts and pints (whole numbers), then calculates and returns an output of the total number of gallons (a floating-point value). There are 4 quarts in a gallon, and 2 pints in a quart. Use appropriate parameter passing and return mechanisms. Use appropriate datatypes. For example, with inputs of 4 quarts and 4 pints, the result would be 1.5 gallons. Use proper code formatting techniques. Do not write a main routine. Your function does not do cin or cout.
3.
Write a function that converts an input of some integer number of nickels into outputs of integer numbers of dollars, quarters, and nickels. Do not write a main function. Your function does not do cin or cout. Your function will have four parameters. Make sure you use appropriate parameter passing techniques! Your function will be a void function. There are 5 nickels in a quarter, and 20 nickels in a dollar. For example, if the total number of nickels input is 27, the results are 1 dollar, 1 quarter, and 2 nickels.
Explanation / Answer
1. void fun(int arr[],int size)
{
cout<<"please enter "<<size"<<"integers numbers between -100 and +100"<<endl;
for(int i=0;i<size;)
{
cin>>arr[i];
if(arr[i]<-100 || arr[i] >100)
{
cout<<"this is an invalid input try again"<<endl;
continue;
}
else
i++;
}
}
3. #include <iostream>
using namespace std;
int count(int,int&,int&,int&);
int main()
{int nickels,dollars,quarters;
cout<<"Enter number of nickels: ";
cin>>nickels;
count(nickels,dollars,quarters,nickels);
cout<<"you have "<<dollars<<" dollars "<<quarters<<" quarters "<<nickels<<" nickels ";
system("pause");
return 0;
}
int count(int in,int& d,int& q,int& n)
{int val;
val=in*5;
d=val/100;
val%=100;
q=val/25;
n=val%25/5;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.