I am trying to make a program that calculates the average score of class and counting the number of A, B, C, D students. Now I am trying another idea: If the test scores are randomly given to students(between 60 to 100), how can I input those random scores into an array? Mine requires users to input all scores one by one. I would like to know how to fill in the array automatically.
#include <iostream>
#include <cstdlib>
using namespace std;
double Average(double *scores, int N)
{
int i;
double total = 0;
for(i = 0; i < N; i++)
{
total = total+scores[i];
}
return total / N;
}
int Agrade(double *scores, int N)
{
int i;
int count = 0;
for(i = 0; i < N; i++)
{
if(scores[i] >= 90 && scores[i] <= 100) count++;
}
return count;
}
int Bgrade(double *scores, int N)
{
int i;
int count = 0;
for(i=0; i < N; i++)
{
if(scores[i] >=80 && scores[i] < 90) count ++;
}
return count;
}
int Cgrade(double *scores, int N)
{
int i;
int count = 0;
for(i=0; i < N; i++)
{
if(scores[i] >=70 && scores[i] < 80) count ++;
}
return count;
}
int Dgrade(double *scores, int N)
{
int i;
int count = 0;
for(i=0; i < N; i++)
{
if(scores[i] >=60 && scores[i] < 70) count ++;
}
return count;
}
int Fgrade(double *scores, int N)
{
int i;
int count = 0;
for(i=0; i < N; i++)
{
if(scores[i] < 60) count ++;
}
return count;
}
int main(){
int i;
int N;
double *scores;
std::cout<<"How many test scores? "<<endl;
cin>>N;
if(N<1){
std::cout<<"Invalid input. try again"<<endl;
}
else if(N>25)
{
std::cout<<"1-25 only."<<endl;
}
else if(N>0 && N<25){
std::cout<<"Total number of test is: "<< N << endl;
}
scores = new double[N];
for(i = 0; i < N; i++)
{
cout << "Randomly generating score of students" << i + 1 << ": ";
cout << (rand() % 40 + 60) << endl; //Trying to give random scores between 60-100
if(!(cin >> scores[i]) || scores[i] < 0 || scores[i] > 100)
{
if(!cin)
{
cin.clear();
cin.ignore(1000, '\n');
}
cout << "Score must be between 0 to 100.\n\n"; i--; continue;
}
}
double averagescore = Average(scores, N);
int scoreAcount = Agrade(scores, N);
int scoreBcount = Bgrade(scores, N);
int scoreCcount = Cgrade(scores, N);
int scoreDcount = Dgrade(scores, N);
int scoreFcount = Fgrade(scores, N);
cout << "The average test score : " << averagescore << endl;
cout << "The number of A grades : " << scoreAcount << endl;
cout << "The number of B grades : " << scoreBcount << endl;
cout << "The number of C grades : " << scoreCcount << endl;
cout << "The number of D grades : " << scoreDcount << endl;
cout << "The number of F grades : " << scoreFcount <<endl;
cout << endl;
return 0;
}
Can I just modify this part to make it work?
for(i = 0; i < N; i++)
{
cout << "Randomly generating score of students" << i + 1 << ": ";
cout << (rand() % 40 + 60) << endl; //Trying to give random scores between 60-100
if(!(cin >> scores[i]) || scores[i] < 0 || scores[i] > 100)
{
if(!cin)
{
cin.clear();
cin.ignore(1000, '\n');
}
cout << "Score must be between 0 to 100.\n\n"; i--; continue;
}
}
or do I need to modify all functions?
If what you want is to assign result of std::rand() function to all elements in array, you should take a look at std::generate function from <algorithm> header, which does exactly what you want. Take a look at this simple example:
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
int main() {
std::srand(0);
const int N = 5;
std::vector<int> scores(N);
std::generate(scores.begin(), scores.end(), [](){return std::rand() % 40 + 60; });
for(auto s : scores) {
std::cout << s << ' ';
}
}
This will fill vector scores with randomly generated numbers from specified interval using std::generate function and lambda function given as its third argument that returns random number.
In your case, if you're not allowed to use std::vector, you can still do it with plain C-arrays, like this:
int scores[5];
std::generate(std::begin(scores), std::end(scores), [](){return std::rand() % 40 + 60; });
Unfortunately, std::begin and std::end functions cannot be applied straight-forward to dynamically allocated arrays, but this still should work in your case:
const int N = 5;
double* scores = new double[N];
std::generate(scores, scores+N, [](){return std::rand() % 40 + 60; });
for(int i=0; i<N; ++i) {
std::cout << scores[i] << ' ';
}
// remember to release memory allocated using new
You need to seed the random number generator to make sure the random numbers have a reasonably random seed. So before the for loop you mentioned, you need to call something like srand(time(NULL)) and include time.h in your code. That should be enough.
And just as an aside, in your code, I only see allocation of the scores array. Remember to delete! Even better, use vectors throughout.
Related
I finished this code homework assignment tonight. I thought I was done, but I just realized that my "Average" value is coming out wrong with certain values. For example: When my professor entered the values 22, 66, 45.1, and 88 he got an "Average" of 55.27. However, when I enter those values in my program, I get an "Average" of 55.25. I have no idea what I am doing wrong. I was pretty confident in my program until I noticed that flaw. My program is due at midnight, so I am clueless on how to fix it. Any tips will be greatly appreciated!
Code Prompt: "Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible."
Professor Notes: The book only states, "Input Validation: Do not accept negative numbers for test scores." We also need to have input validation for the number of scores. If it is negative, including 0, the program halts, we should consider this situation for 'counter' not to be negative while we have a loop to enter numbers. So negative numbers should be rejected for the number of scores and the values of scores.
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
void showArray(double* array, int size);
double averageArray(double* array, int size);
void orderArray(double* array, int size);
int main()
{
double* scores = nullptr;
int counter;
double numberOfScores;
cout << "\nHow many test scores will you enter? ";
cin >> numberOfScores;
if (numberOfScores < 0) {
cout << "The number cannot be negative.\n"
<< "Enter another number: ";
cin >> numberOfScores;
}
if (numberOfScores == 0) {
cout << "You must enter a number greater than zero.\n"
<< "Enter another number: ";
cin >> numberOfScores;
}
scores = new double[numberOfScores];
for (counter = 0; counter < numberOfScores; counter++) {
cout << "Enter test score " << (counter + 1) << ": ";
cin >> *(scores + counter);
if (*(scores + counter) < 0) {
cout << "Negative scores are not allowed. " << endl
<< "Enter another score for this test : ";
cin >> *(scores + counter);
}
}
orderArray(scores, counter);
cout << "\nThe test scores in ascending order, and their average, are: " << endl
<< endl;
cout << " Score" << endl;
cout << " -----" << endl
<< endl;
showArray(scores, counter);
cout << "\nAverage Score: "
<< " " << averageArray(scores, counter) << endl
<< endl;
cout << "Press any key to continue...";
delete[] scores;
scores = nullptr;
system("pause>0");
}
void orderArray(double* array, int size)
{
int counterx;
int minIndex;
int minValue;
for (counterx = 0; counterx < (size - 1); counterx++) {
minIndex = counterx;
minValue = *(array + counterx);
for (int index = counterx + 1; index < size; index++) {
if (*(array + index) < minValue) {
minValue = *(array + index);
minIndex = index;
}
}
*(array + minIndex) = *(array + counterx);
*(array + counterx) = minValue;
}
}
double averageArray(double* array, int size)
{
int x;
double total{};
for (x = 0; x < size; x++) {
total += *(array + x);
}
double average = total / size;
return average;
}
void showArray(double* array, int size)
{
for (int i = 0; i < size; i++) {
cout << " " << *(array + i) << endl;
}
}
I try to start my answers with a brief code review:
#include <iostream>
#include <iomanip>
using namespace std; // Bad practice; avoid
void showArray(double* array, int size);
double averageArray(double* array, int size);
void orderArray(double* array, int size);
int main()
{
double* scores = nullptr;
int counter;
double numberOfScores;
cout << "\nHow many test scores will you enter? ";
cin >> numberOfScores;
// This is not input validation, I can enter two consecutive bad values,
// and the second one will be accepted.
if (numberOfScores < 0) {
// Weird formatting, this blank line
cout << "The number cannot be negative.\n"
<< "Enter another number: ";
cin >> numberOfScores;
}
// The homework, as presented, doesn't say you have to treat 0 differently.
if (numberOfScores == 0) {
cout << "You must enter a number greater than zero.\n"
<< "Enter another number: ";
cin >> numberOfScores;
}
scores = new double[numberOfScores];
// Declare your loop counter in the loop
for (counter = 0; counter < numberOfScores; counter++) {
cout << "Enter test score " << (counter + 1) << ": ";
cin >> *(scores + counter);
if (*(scores + counter) < 0) {
cout << "Negative scores are not allowed. " << endl
<< "Enter another score for this test : ";
cin >> *(scores + counter);
}
}
orderArray(scores, counter); // Why not use numberOfScores?
cout << "\nThe test scores in ascending order, and their average, are: " << endl
<< endl;
cout << " Score" << endl;
cout << " -----" << endl
<< endl;
showArray(scores, counter); // Same as above.
cout << "\nAverage Score: "
<< " " << averageArray(scores, counter) << endl
<< endl;
cout << "Press any key to continue...";
delete[] scores;
scores = nullptr;
system("pause>0"); // Meh, I suppose if you're on VS
}
void orderArray(double* array, int size)
{
int counterx;
int minIndex;
int minValue; // Unnecessary, and also the culprit
// This looks like selection sort
for (counterx = 0; counterx < (size - 1); counterx++) {
minIndex = counterx;
minValue = *(array + counterx);
for (int index = counterx + 1; index < size; index++) {
if (*(array + index) < minValue) {
minValue = *(array + index);
minIndex = index;
}
}
*(array + minIndex) = *(array + counterx);
*(array + counterx) = minValue;
}
}
double averageArray(double* array, int size)
{
int x;
double total{};
for (x = 0; x < size; x++) {
total += *(array + x);
}
double average = total / size;
return average;
}
void showArray(double* array, int size)
{
for (int i = 0; i < size; i++) {
cout << " " << *(array + i) << endl;
}
}
When you are sorting your array, you keep track of the minValue as an int and not a double. That's why your average of the sample input is incorrect. 45.1 is truncated to 45 for your calculations. You don't need to keep track of the minValue at all. Knowing where the minimum is, and where it needs to go is sufficient.
But as I pointed out, there are some other serious problems with your code, namely, your [lack of] input validation. Currently, if I enter two consecutive bad numbers, the second one will be accepted no matter what. You need a loop that will not exit until a good value is entered. It appears that you are allowed to assume that it's always a number at least, and not frisbee or any other non-numeric value.
Below is an example of what your program could look like if your professor decides to teach you C++. It requires that you compile to the C++17 standard. I don't know what compiler you're using, but it appears to be Visual Studio Community. I'm not very familiar with that IDE, but I imagine it's easy enough to set in the project settings.
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// Assumes a number is always entered
double positive_value_prompt(const std::string& prompt) {
double num;
std::cout << prompt;
do {
std::cin >> num;
if (num <= 0) {
std::cerr << "Value must be positive.\n";
}
} while (num <= 0);
return num;
}
int main() {
// Declare variables when you need them.
double numberOfScores =
positive_value_prompt("How many test scores will you enter? ");
std::vector<double> scores;
for (int counter = 0; counter < numberOfScores; counter++) {
scores.push_back(positive_value_prompt("Enter test score: "));
}
std::sort(scores.begin(), scores.end());
for (const auto& i : scores) {
std::cout << i << ' ';
}
std::cout << '\n';
std::cout << "\nAverage Score: "
<< std::reduce(
scores.begin(), scores.end(), 0.0,
[size = scores.size()](auto mean, const auto& val) mutable {
return mean += val / size;
})
<< '\n';
}
And here's an example of selection sort where you don't have to worry about the minimum value. It requires that you compile to C++20. You can see the code running here.
#include <iostream>
#include <random>
#include <vector>
void selection_sort(std::vector<int>& vec) {
for (int i = 0; i < std::ssize(vec); ++i) {
int minIdx = i;
for (int j = i + 1; j < std::ssize(vec); ++j) {
if (vec[j] < vec[minIdx]) {
minIdx = j;
}
}
int tmp = vec[i];
vec[i] = vec[minIdx];
vec[minIdx] = tmp;
}
}
void print(const std::vector<int>& v) {
for (const auto& i : v) {
std::cout << i << ' ';
}
std::cout << '\n';
}
int main() {
std::mt19937 prng(std::random_device{}());
std::uniform_int_distribution<int> dist(1, 1000);
std::vector<int> v;
for (int i = 0; i < 10; ++i) {
v.push_back(dist(prng));
}
print(v);
selection_sort(v);
print(v);
}
I opted not to give your code the 'light touch' treatment because than I would have done your homework for you, and that's just not something I do. However, the logic shown should still be able to guide you toward a working solution.
I have a problem with this piece of code, I'm trying to print the EVEN and ODD numbers, but there is a problem when it comes to show them, the vectors don't save the numbers as I'm expecting.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int vect[n], even[n], odd[n]; // CREATING VECTORS LIMIT AFTER "n"
for(int i = 1; i <= n; ++i) { // ENTERING The ELEMENS IN VECTOR
cin >> vect[i];
}
for(int i = 1; i <= n; ++i) {
if(vect[i] % 2 != 0) {
odd[i] = vect[i]; // I think that here's the problem, the vectors don't save the right numbers.
} /// VERIFYING IF THE NUMBER IS ODD OR EVEN.
else if (vect[i] % 2 == 0) {
even[i] == vect[i];
}
}
for(int i = 1; i <= n; ++i) {
cout << even[i] << " " << endl; /// PRINTING THE ODD AND EVEN numbers.
cout << odd[i] << " " << endl;
}
return 0;x
}
I have fixed the problem, thanks all for help.
Now it works perfectly.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int vect[n], even[n], odd[n], z = 0, x = 0; // CREATING VECTORS LIMIT AFTER "n"
for(int i = 1; i <= n; ++i) { // ENTERING The ELEMENS IN VECTOR
cin >> vect[i];
}
for(int i = 1; i <= n; ++i) {
if(vect[i] % 2 != 0) {
odd[1+z] = vect[i];
z++;
// I think that here's the problem, the vectors don't save the right numbers.
} /// VERIFYING IF THE NUMBER IS ODD OR EVEN.
else if (vect[i] % 2 == 0) {
even[1+x] = vect[i];
x++;
}
}
for(int i = 1; i <= x; i++) {
cout << even[i] << " ";
}
cout << endl;
for(int i = 1; i <= z; i++) {
cout << odd[i] << " ";
}
return 0;
}
Considering the hints of the comments, your program shall be changed into this:
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, number;
cin >> n;
vector<int> vect, even, odd; // CREATING DYNAMIC VECTORS
for(int i = 0; i < n; ++i) { // ENTERING THE ELEMENTS IN VECTOR
cin >> number;
vect.push_back(number);
}
for(int i = 0; i < n; ++i) {
if(vect[i] % 2 != 0) { /// VERIFYING IF THE NUMBER IS ODD OR EVEN.
odd.push_back(vect[i]);
}
else {
even.push_back(vect[i]);
}
}
for (int i = 0; i < n; ++i)
cout << vect[i] << " ";
cout << endl;
/// PRINTING THE ODD AND EVEN NUMBERS.
for (auto& val : odd)
cout << val << " ";
cout << endl;
for (auto& val : even)
cout << val << " ";
cout << endl;
return 0;
}
It uses the vector container of STL for your arrays, start the indexing at 0 and prints out the resulting arrays separately, as the number of odd and of even entries might be different.
Hope it helps?
With standard, you might use std::partition (or stable version) to solve your problem:
void print_even_odd(std::vector<int> v)
{
auto limit = std::stable_partition(v.begin(), v.end(), [](int n){ return n % 2 == 0; });
std::cout << "Evens:";
// Pre-C++20 span:
// for (auto it = v.begin(); it != limit; ++it) { int n = *it;
for (int n : std::span(v.begin(), limit)) {
std::cout << " " << n;
}
std::cout << std::endl;
std::cout << "Odds:";
for (int n : std::span(limit, v.end())) {
std::cout << " " << n;
}
std::cout << std::endl;
}
Demo
I am trying to write a program that will count the number of 5s in a number and display it. So if the user enters:
52315
Then the program should ouptut:
Yes, there are '5's and they're 2
Here is my code but there is something wrong with it.
{
int n,m;
int count = 0;
cout << "Enter an: ";
cin >> n;
int *arr;
arr = new int[count];
// Getting digits from number
while (n > 0)
{
count++;
m = n%10;
n = n/10;
//Trying to put every digit in an array
for (int i = 0; i<count; i++)
{
cin>>arr[i];
arr[i] = m;
cout << arr[i];
}
int even = 5;
//Trying to see if there's a digit 5 in inputed number and how many if so.
for (int j = 0; j<count; j++)
{
if (arr[j]==even)
{
cout << "Yes, there's a digit '5' " << endl;
s++;
}
}
cout << "Count of '5's : " << even;
delete[] arr;
}
return 0;
}
This
for (int i = 0; i<count; i++)
{
cin >> arr[i];
}
You're trying to populate the array with the another user input rather than the existing one.
You also can do it without the array:
int count = 0;
int n;
cin >> n;
do {
if (n%10 ==5) count++;
n /= 10;
} while (n);
cout << "Count of '5's : " << count;
This should do it for every number.
If you only want to know a special number like 5, just remove the for-loop and print count[theNumberYouWantToKnow].
#define BASE 10
void output() {
int givenNumber;
cout << "Please enter a number: ";
cin >> givenNumber;
int count[BASE] = { 0 };
while(givenNumber > 0) {
int digit = givenNumber % BASE;
givenNumber /= BASE;
count[digit]++;
}
for(int i = 0; i < BASE; i++) {
cout << "Found the number " << i << " " << count[i] << " times." << endl;
}
}
How to count how many times a loop has been executed my code doesn't work as I expected it,
find the primes numbers before n number input by user and display them and count how many
numbers are in total
ex.
number input lets say 7,
and there are 3 numbers before 7
so it displays 2,3,5,7 and there are 3 prime numbers before 7
#include <iostream>
using namespace std;
int main()
{
int n, i, k;
int counter = 0;
bool isprime;
cout << "Enter a positive integer n: ";
cin >> n;
for(int k = 2; k <= n; k++)
{
isprime = true;
for(int i = 2; i <= k - 1; i++)
if(k%i == 0)
{
isprime = false;
}
if(isprime)
cout << k << "\t";}
cout << "\nThere are " << counter << " primes less than " << n;
return 0;
}
In your example, counter is never modified from its initial value. Try having it count what you want to count.
Added: ...
BTW. Prefer
for (i = 0; i < n; ++i)
for looping. The "i < n" is more idiomatic (easier to read) and the ++i normally will be more efficient than i++.
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int num;
int count = 0;
cout << "Enter your range: ";
cin >> num;
for(int i = 1; i <= num; i++)
{
count = 0;
for(int j = 2; j <= sqrt(i); j++)
{
if(i % j == 0)
{
count++;
break;
}
}
if(count == 0 && i != 1)
cout << i << " ";
}
cout << endl;
}
This will increase the count variable every time there's a prime number.
#include <iostream>
using namespace std;
int main()
{
int n, i, k;
int counter = 0;
bool isprime;
cout << "Enter a positive integer n: ";
cin >> n;
for(int k = 2; k <= n; k++)
{
isprime = true;
for(int i = 2; i <= k - 1; i++)
if(k%i == 0)
{
isprime = false;
}
if(isprime)
{
cout << k << "\t";
counter++;
}
}
cout << "\nThere are " << counter - 1<< " primes less than " << n;
return 0;
}
As said above counter is not incremented.
You should make a function
isPrime?(int n)
{
int sqrt_n = sqrt(n)
for(int i = 2; i <= sqrt_n; i++){ //You could check only to sqrt(n)
if(n%i == 0)
{
return false;
}
}
return true;
}
And then you could use that function as follow:
int main()
{
int n, i, k;
int counter = 0;
cout << "Enter a positive integer n: ";
cin >> n;
for(int k = 2; k <= n; k++)
{
if(isPrime?(k)) {
counter++;
cout << k << "\t";
}
cout << "\nThere are " << counter << " primes less than " << n;
return 0;
}
I need help with getting this users input of an integer and retrieving the even numbers and displaying them with spaces.I already have the input processed into an array and have it reversed (thanks to stackoverflow) now need to extract the even numbers from the array and display them.
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int evenNumbers(char even[], int num[], int indexing[]);
int main()
{
char integers[5];
int numbers[5];
int even[5] = {0,2,4,6,8};
int evens;
cout << "Please enter an integer and press <ENTER>: " << endl;
for (int j = 0; j < 5; j++)
cin >> integers[j];
for (int j = 0; j < 5; j++)
{
numbers[j]= integers[j] - '0';
}
cout << endl;
for (int j = 5; j > 0; j--)
{
cout << integers[j - 1] << " ";
}
cout << endl;
//having problems finding the even numbers and displaying the even numbers
//from the users input of integers, i have only learned how to display the
//subscript by a linear search
evens = evenNumbers(integers, numbers, even);
if (evens == -1)
cout << "There are no even numbers" << endl;
else
{
cout << "The even numbers are: " << (evens + 1) << endl;
}
system("pause");
return 0;
}
int evenNumbers(char even[], int num[], int indexing[])
{
int index = 0;
int position = -1;
bool found = false;
for (int j = 0; j < 5; j++)
{
num[j]= even[j] - '0';
}
while (index < 5)
{
if (num[index] == indexing[index])
{
found = true;
position = index;
}
index++;
}
return position;
}
If you want to display the even numbers from the array integers you can use a simple for loop and if statement:
for(int i = 4; i >= 0; i--)
{
if(integers[i] % 2 == 0)
cout << integers[i] << " ";
}
Your approach is all wrong, you can't detect even numbers by searching a list, you need a mathematical test for evenness. Write a function called is_even which tests one number and returns true if it is even and false if it is not. Then you can use that function, very simply, like this
for (int j = 0; j < 5; j++)
{
if (is_even(integers[j]))
cout << integers[j] << " ";
}
cout << endl;
Now you just need to write the is_even function.
void evennumbers(int num[])
{
for(int i=0;i<5;i++)
{
if(num[i]%2==0)
cout<<num[i]<<" ";
}
}
And avoid taking input to char what if user enters a number with more than one digit
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
void validNum(char valid[]);
void reverseNum(char rev[], int num2[]);
void evenNumbers(char even[], int num3[]);
void oddNumbers(char odd[], int num4[]);
int main()
{
char integer[5];
int number[5];
cout << "Your number is: ";
validNum(integer);
cout << "Your number in reverse is: ";
reverseNum(integer, number);
cout << "Even numbers: ";
evenNumbers(integer, number);
cout << endl;
cout << "Odd numbers: ";
oddNumbers(integer, number);
cout << endl;
system("pause");
return 0;
}
void validNum(char valid[])
{
char ch;
cout << "Please enter an integer and press <ENTER>: " << endl;
ch = cin.get;
while (ch < 0 || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z')
{
cout << "ERROR: Please enter a positive integer and press <ENTER>: ";
for (int i = 0; i < 5; i++)
cin >> valid[i];
}
for (int j = 0; j < 5; j++)
{
cout << valid[j] - '0';
}
}
void reverseNum(char rev[], int num2[])
{
for (int j = 0; j < 5; j++)
{
num2[j]= rev[j] - '0';
}
cout << endl;
for (int j = 5; j > 0; j--)
{
cout << rev[j - 1]<< " ";
}
cout << endl;
}
void evenNumbers(char even[], int num3[])
{
for (int i = 0; i < 5; i++)
{
if (even[i] % 2 == 0)
{
cout << num3[i] << " ";
}
}
}
void oddNumbers(char odd[], int num4[])
{
for (int i = 0; i < 5; i++)
{
if (odd[i] % 2 == 1)
{
cout << num4[i] << " ";
}
}
}