My program is working as I want it to work (It is on Bosnian language so the cout of the program is not that important). The program is about reading some text from file and then couting what I want to
The only problem I have with this program is that for some reason it is showing the two 0 0 at the end of the text file even though I do not have it in my text file
Here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
struct proizvod
{
char naziv[100];
char proizvodac[100];
int cijena = 0;
int kolicina = 0;
};
bool poredjenje(proizvod a, proizvod b)
{
if (a.cijena != b.cijena )
return a.cijena > b.cijena;
}
void sortiranje(proizvod a[], int n)
{
sort(a, a+n, poredjenje);
}
int main()
{
ifstream datoteka;
datoteka.open("proizvodi.txt.txt");
int brojStvari = 0;
int sumaProizvoda = 0;
int ukupnaVrijednost = 0;
char* spisakProizvoda[100];
int brojFIAT = 0;
int spisakCijena = 0;
proizvod automobili[100];
if (datoteka.fail())
{
cout << "Ne postojeca datoteka";
exit(1);
}
while (datoteka.good() && !datoteka.eof())
{
datoteka >> automobili[brojStvari].naziv >> automobili[brojStvari].proizvodac >> automobili[brojStvari].cijena >> automobili[brojStvari].kolicina;
++brojStvari;
++sumaProizvoda;
}
for (int i = 0; i < brojStvari; i++)
{
cout << automobili[i].naziv << " " << automobili[i].proizvodac << " " << automobili[i].cijena << " " << automobili[i].kolicina << endl;
}
for (int i = 0; i < brojStvari; i++)
{
ukupnaVrijednost += automobili[i].cijena;
if (automobili[i].kolicina == 0)
{
spisakProizvoda[i] = automobili[i].proizvodac;
}
else if (automobili[i].proizvodac == "FIAT")
{
brojFIAT++;
}
}
char pomocna[100];
cout << endl;
cout << "Ukupan broj proizvoda u datoteci: " << sumaProizvoda << endl;
cout << "Ukupan vrijednost proizvoda u datoteci: " << ukupnaVrijednost << endl;
cout << "Spisak automobila sa cijenom 0 su: ";
for (int i = 0; i < brojStvari; i++)
{
if (!spisakProizvoda[i])
{
cout << "Ne postoje ti proizvodi " << endl;
break;
}
else
cout << spisakProizvoda[i] << endl;
}
cout << "Broj prozivoda koji proizvodi FIAT: " << brojFIAT << endl;
cout << "Sortirani proizvodi prema cijeni: " << endl;
sortiranje(automobili, brojStvari);
for (int i = 0; i < brojStvari; i++)
{
cout << automobili[i].proizvodac << endl;
}
return 0;
}
And here is the cout
Golf Volskwagen 5000 5
AudiRS5 Audi 50000 3
0 0
Ukupan broj proizvoda u datoteci: 3
Ukupan vrijednost proizvoda u datoteci: 55000
Spisak automobila sa cijenom 0 su: Ne postoje ti proizvodi
Broj prozivoda koji proizvodi FIAT: 0
Sortirani proizvodi prema cijeni:
Audi
Volskwagen
Can anybody tell me what is the problem ?
P.S : Sorry if you do not understand the program itself I apologize sincerely
You are seeing the extra 0 0 at end most likely due to an extra empty line at end of proizvodi.txt.txt file. This happens because the new line is also accepted as input but since there are no entries, the entries in struct proizvod retain default 0 values for cijena and kolicina which gets printed out as 0 0.
Update your main() code to reading file like follow and it will work as expected:
while (datoteka >> automobili[brojStvari].naziv >>
automobili[brojStvari].proizvodac >> automobili[brojStvari].cijena >>
automobili[brojStvari].kolicina) {
++brojStvari;
++sumaProizvoda;
}
Related
we were supposed to create a program that can memorize drugs data for a farmacy we were supposd to make 3 function 1 for searching using the code 2 to show the understock in alphabetical description order and 3 to save and load the memorized data from a file called "dati.txt" but we ran in a dirty data problem the program write dirty data or read dirty data i can't figure out if is the loading or the writing pls help me
ps i'm new to programming and i m still learnign
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
#define Num 300
int n = 0;
FILE* file;
struct s_farmaci {
int codice;
string descrizione;
float prezzo;
int disponibilita;
};
void bubblesort(s_farmaci vet[], int num);
void sottoscorta(s_farmaci vet[], int tanti);
int ricercabin(s_farmaci vet[], int inizio, int fine, int codice);
int menu();
void caricamento(s_farmaci farmaco[]);
void mostrafarmaco(s_farmaci farmaco[], int indice);
void scambia(s_farmaci v[], int i, int j);
void salvahdd(s_farmaci farmaco[]);
void caricahdd(s_farmaci farmaco[]);
int main()
{
s_farmaci farmaco[Num];
int scelta;
int codicericerca;
int trovato = -1;
caricahdd(farmaco);
system("pause");
scelta = menu();
do
{
switch (scelta) {
case 4:
{
cout << "stai per uscire dal programma" << endl;
salvahdd(farmaco);
cout << "dati salvati correttamente correttamente" << endl;
break;
}
case 1:
{
caricamento(farmaco);
break;
}
case 2:
{
bubblesort(farmaco, n);
cout << "quale codice vuoi cercare? ";
cin >> codicericerca;
trovato = ricercabin(farmaco, 0, n - 1, codicericerca);
if (trovato == -1)
cout << "Prodotto non trovato!" << endl;
else {
cout << "prodotto trovato: " << endl;
mostrafarmaco(farmaco, trovato);
}
break;
}
case 3:
{
sottoscorta(farmaco, n);
break;
}
default:
{
cout << " errore scelta non valida riprova " << endl;
break;
}
}
system("pause");
scelta = menu();
} while (scelta != 0);
return 0;
}
//bubblesort of the code
void bubblesort(s_farmaci vet[], int num)
{
int tempcodice;
float tempprezzo;
int tempquantita;
string tempdescrizzione;
bool scambi = false;
do {
scambi = false;
for (int i = 0; i < num - 1; i++) {
if (vet[i].codice > vet[i + 1].codice) {
scambi = true;
tempcodice = vet[i].codice;
vet[i].codice = vet[i + 1].codice;
vet[i + 1].codice = tempcodice;
tempprezzo = vet[i].prezzo;
vet[i].prezzo = vet[i + 1].prezzo;
vet[i + 1].prezzo = tempprezzo;
tempquantita = vet[i].disponibilita;
vet[i].disponibilita = vet[i + 1].disponibilita;
vet[i + 1].disponibilita = tempcodice;
tempdescrizzione = vet[i].descrizione;
vet[i].descrizione = vet[i + 1].descrizione;
vet[i + 1].descrizione = tempdescrizzione;
}
}
} while (scambi == true);
}
//menu
int menu()
{
system("cls");
int scelta;
cout << "-----------------------------" << endl;
cout << "- BENVENUTI -" << endl;
cout << "-----------------------------" << endl;
cout << "- -" << endl;
cout << "- 1 caricamento -" << endl;
cout << "- 2 ricerca -" << endl;
cout << "- 3 mostra -" << endl;
cout << "- 4 salva -" << endl;
cout << "- -" << endl;
cout << "-----------------------------" << endl;
cout << "-- inserici numero: ";
cin >> scelta;
return scelta;
}
//get drugs information
void caricamento(s_farmaci farmaco[]) {
system("cls");
cout << "inserisci il " << n + 1 << " farmaco" << endl;
//inserisco il codice
cout << "insersci il codice: ";
cin >> farmaco[n].codice;
//inserisco la descrizione
cout << "inserisci la descrizione del farmaco: ";
cin.ignore();
getline(cin, farmaco[n].descrizione);
//inserisco il prezzo
cout << "inserici il prezzo: ";
cin >> farmaco[n].prezzo;
//inserico la disponibilita
cout << "inserci quanti farmaci sono disponibili: ";
cin >> farmaco[n].disponibilita;
cout << endl;
n++;
}
/show memorized drugs
void mostrafarmaco(s_farmaci farmaco[], int indice) {
cout << endl;
cout << "codice farmaco :" << farmaco[indice].codice << endl;
cout << "descrizione farmaco :" << farmaco[indice].descrizione << endl;
cout << "prezzo farmaco :" << farmaco[indice].prezzo << endl;
cout << "quantita disponibili :" << farmaco[indice].disponibilita << endl;
}
//binary search
int ricercabin(s_farmaci vet[], int inizio, int fine, int codice) {
int medio;
if (inizio > fine)
return -1;
else {
medio = (inizio + fine) / 2;
if (codice == vet[medio].codice)
return medio;
else
if (codice > vet[medio].codice)
return ricercabin(vet, medio + 1, fine, codice);
else
return ricercabin(vet, inizio, medio - 1, codice);
}
}
//show me understock
void sottoscorta(s_farmaci vet[], int tanti) {
int tempcodice;
float tempprezzo;
int tempquantita;
for (int x = 0; x < tanti; x++) {
//algoritmo di ordinamento
int i, j;
string temp;
//sorting farmacs description
for (j = 0; j < tanti - 1; j++)
for (i = 0; i < tanti - 1; i++)
if (vet[i].descrizione > vet[i+1].descrizione)
scambia(vet, i, i+1);
}
for (int k = 0; k < tanti; k++) {
if (vet[k].disponibilita < 3) {
cout << endl;
cout << " il codice del farmaco e':" << vet[k].codice << endl;
cout << " la descrizione del farmaco e':" << vet[k].descrizione << endl;
cout << " il prezzo del farmaco e':" << vet[k].prezzo << endl;
cout << " la disponibilita' del farmaco e':" << vet[k].disponibilita << endl;
}
}
}
//exchange variables
void scambia(s_farmaci v[], int i, int j) {
s_farmaci temp;
temp = v[i];
v[i] = v[j];
v[j] = temp;
}
//get file from hdd
void caricahdd(s_farmaci farmaco[]) {
n = 0;
if ((file = fopen("dati.txt", "rb")) == NULL)
cout << "errore apertura file" << endl;
else {
while (!feof(file)) {
fread(&farmaco[n], sizeof(s_farmaci), 1, file);
n++;
}
fclose(file);
cout << "dati caricati correttamente" << endl;
}
}
//save file on hdd
void salvahdd(s_farmaci farmaco[]) {
if ((file = fopen("dati.txt", "wb")) == NULL)
cout << "errore apertura file" << endl;
else {
for (int i = 0; i <= n; i++) {
fwrite(&farmaco[i], sizeof(s_farmaci), 1, file);
}
fclose(file);
}
}
You say read-file get dirty data in array;
But it's not dirty data
fread(&farmaco[n], sizeof(s_farmaci), 1, file);
It only means that, read some data and put in the address(&farmaco[n]).But C++ don't know how to correctly set the data for the member of the array.
For Example:
/*this is the data file*/
19 /*set age value*/
Hello /*set name value*/
20 /*set age value*/
Exam /*set name value*/
And a struct has two members
struct people
{
int age;
string name;
}
The array people[2],this is how to read data and set value
/*read the first data and set people[0].age*/
people[0].age = 19
/*read the second data and set people[0].name*/
people[0].name= Hello
/*read the third data and set people[1].age*/
people[1].age = 19
/*read the fourth data and set people[1].name*/
people[1].name= Hello
/*and so on*/
I am trying to write a program to get student data (student id, subject results) from user input and align them based on their total marks. But when I try to input till the 5th student the stack smashing detected the error that occured. And I can't find a way to solve this problem...
It would be really helpful if anyone can give me some advice about it. Thanks in advance
My code:
h file
#include <string>
#include <iostream>
using namespace std;
class student
{
private:
char id[100];
int eng, math, jan, total;
public:
void getInput(void);//ユーザーから学生のデータを入力してもらう
void putInput(void);//最後の結果を表示する
friend void sort(student std[]);//総得点の高い順に各人のデータを並べ替える
friend void avg(student std[]);//各科目と総得点の平均値を計算する
};
cpp file
#include <string>
#include <iostream>
#include "report1.h"
using namespace std;
#define MAX 10
void student::getInput(void)//ユーザーから学生のデータを入力してもらう
{
cout << "IDを入力してください:";
cin >> id;
cout << "英語の点数:";
cin >> eng;
cout << "数学の点数:";
cin >> math;
cout << "国語の点数:";
cin >> jan;
total = eng + math + jan;
}
void student::putInput(void)//最後の結果を表示する
{
cout << id << "\t" << eng << "\t" << math << "\t" << jan << "\t" << total << endl;
}
void sort(student std[])//総得点の高い順に各人のデータを並べ替える
{
int i, j;
for ( i = 0; i < MAX-1; i++)
{
for ( j = i+1; j < MAX; j++)
{
if (std[i].total < std[j].total)//一つ後ろのデータが確認中のデータより大きいなら、並べ替える
{
student temp;
temp = std[i];
std[i] = std[j];
std[j] = temp;
}
}
}
}
void avg(student std[])//各科目と総得点の平均値を計算する
{
int i;
int eng_total, math_total, jan_total, total_total;
double eng_avg, math_avg, jan_avg, total_avg;
eng_total = 0;
math_total = 0;
jan_total = 0;
total_total = 0;
for ( i = 0; i < MAX; i++)
{
eng_total += std[i].eng;
math_total += std[i].math;
jan_total += std[i].jan;
total_total += std[i].total;
}
eng_avg = (double)eng_total/MAX;
math_avg = (double)math_total/MAX;
jan_avg = (double)jan_total/MAX;
total_avg = (double)total_total/MAX;
cout << "Avg\t" << eng_avg << "\t" << math_avg << "\t" << jan_avg << "\t" << total_avg << endl;
}
int main()
{
student std[MAX-1];
int i, j;
for ( i = 0; i < MAX; i++)
{
cout << i+1 << "番目の学生データを入力してください。" << endl;
std[i].getInput();
}
sort(std);
cout << endl;
cout << "ID_No" << "\tEng" << "\tMath" << "\tJan" << "\tTotal" << endl;
for ( i = 0; i < MAX; i++)
{
std[i].putInput();
}
avg(std);
return 0;
}
I am working on a program in which I have a function and I am hoping to time it. Currently, I considered clock_t in the ctime module to be useful, but when I entered the code for timing, I got (I used Dev-C++ to edit) "permission denied". Below is my code:
#include <iostream>
#include <vector>
#include <ctime>
// Initialization
const int maxN = 99999;
int tokens[maxN] = {}; // All the tokens at mission 1
bool use[maxN] = {}; // Status of the tokens (used or not used)
int bag[maxN]; // Bag to put the tokens into
using namespace std;
int ansIdx = 1; // Answer number
char menu() {
// Print menu
cout << "0: terminate\n";
cout << "1: mission 1 - permutations from 1 ~ N\n";
cout << "2: mission 2 - permutations from input\n";
// Ask for input
cout << "Please input a choice (0 ~ 2): ";
char choice;
cin >> choice;
// Valid command?
if (choice >= '0' and choice <= '2') {
return choice;
}
return '\0';
}
int permutations(int depth, int n, int l) {
if (depth == n) {
// Arranged all elements, so cout each of the elements.
cout << "[" << ansIdx << "] ";
for (int i = 0; i < n; i++) cout << bag[i] << " ";
cout << "\n";
ansIdx++;
return l;
}
for (int i = 0; i < n; i++) {
// Else, for each UNUSED element at this layer:
if (use[i] == 0) {
// Put it into bag[i].
bag[depth] = tokens[i];
// Set the status of it used.
use[i] = 1;
// Call recursion.
permutations(depth + 1, n, l+1);
// Backtrack.
use[i] = 0;
}
}
}
int main() {
// Print menu.
cout << "PERMUTATION GENERATOR\n";
char executionMode;
while (executionMode != '0') {
executionMode = menu();
while (executionMode == '\0') {
executionMode = menu();
}
int layers;
clock_t start;
double ms;
switch (executionMode) {
case '1':
cout << "Enter N: ";
int N;
cin >> N;
for (int i = 0; i < N; i++) {
tokens[i] = i + 1;
}
start = clock();
layers = permutations(0, N, 0);
ms = ((double)(clock() - start)) / CLOCKS_PER_SEC;
cout << "L = " << layers << "\n";
cout << "Mission 1: " << ansIdx - 1 << " permutations\n";
cout << "Used: " << ms << "ms\n";
ansIdx = 1;
break;
case '2':
int M = 0;
while (M < 2 or M > 9) {
cout << "Enter length of input (2 ~ 9): ";
cin >> M;
}
for (int i = 0; i < M; i++) {
cout << "Enter a number: ";
cin >> tokens[i];
}
start = clock();
layers = permutations(0, M, 0);
ms = ((double)(clock() - start)) / CLOCKS_PER_SEC;
cout << "L = " << layers << "\n";
cout << "Mission 2: " << ansIdx - 1 << " permutations\n";
cout << "Used: " << ms << "ms";
ansIdx = 1;
break;
}
}
return 0;
}
Can anyone help me? Any suggestions are appreciated.
Currently I have a pre-made 6X6 matrix in a text file like this:
2 6 3 1 0 4
4 2 7 7 2 8
4 7 3 2 5 1
7 6 5 1 1 0
8 4 6 0 0 6
1 3 1 8 3 8
and I made a code that is reading from a file i have made. However I want to have user make a grid for themselves (i.e. 3X3 or 10X10). Which then writes to a text file automatically like in similar fashion and then have that read-in instead. It is a basic memory match card game, so I need to have rand() which generates equal pair so the game can be over when every pair in the grid has been found. Thank you so much for your time!
/*Here are the snippets of my code*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <fstream>
#include <string>
#include <numeric>
#include <limits>
using namespace std;
//global 2d vectors that are associated with the game
vector<vector<int> > game_grid;
vector<vector<int> > hidden_grid;
vector <vector<int> > guessed;
void initialize_grid() {
ifstream input_file;
input_file.open("grid.txt");
int num;
if (input_file) {
for (int i = 0; i < 6; ++i) {
vector<int> row; // game grid
vector<int> row2; // hidden grid
vector<int> row3; // guessed grid
for (int j = 0; j < 6; ++j) {
if (input_file >> num)
row.push_back(num);
row2.push_back(-1);
row3.push_back(0);
}
game_grid.push_back(row);
hidden_grid.push_back(row2);
guessed.push_back(row3);
}
cout << "Get is ready, Challenger!" << endl << endl;
}
else {
cout << "Womp. File open failed!";
}
return;
}
void print_grid() {
cout << "Game grid" << endl;
cout << " -------------------------" << endl;
for (int i = 0; i < 6; ++i) {
cout << " | ";
for (int j = 0; j < 6; ++j) {
cout << game_grid[i][j] << " | ";
}
cout << endl << " -------------------------" << endl;
}
cout << endl;
}
void print_hidden_grid(int r1 = -1, int r2 = -1, int c1 = -1, int c2 = -1) {
cout << "Attempt:" << endl;
if (r1 != -1) {
hidden_grid[r1][c1] = game_grid[r1][c1];
}
if (r2 != -1) {
hidden_grid[r2][c2] = game_grid[r2][c2];
}
for (int i = 0; i < 6; ++i) {
cout << " | ";
for (int j = 0; j < 6; ++j) {
if (hidden_grid[i][j] > -1)
cout << hidden_grid[i][j] << " | ";
else
cout << " | ";
}
cout << endl << " -------------------------" << endl;
}
cout << endl;
if (r1 != -1) {
if (game_grid[r1][c1] == game_grid[r2][c2]) {
guessed[r1][c1] = 1;
guessed[r2][c2] = 1;
cout << "You have a match!" << endl << endl;
}
else {
hidden_grid[r1][c1] = -1;
hidden_grid[r2][c2] = -1;
}
}
cout << endl << endl;
}
void print_current_grid() {
cout << "Current Grid:" << endl;
cout << " -------------------------" << endl;
for (int i = 0; i < 6; ++i) {
cout << " | ";
for (int j = 0; j < 6; ++j) {
if (hidden_grid[i][j] > -1)
cout << hidden_grid[i][j] << " | ";
else
cout << " | ";
}
cout << endl << " -------------------------" << endl;
}
cout << endl << endl;
}
.......
If I well understand you want to auto detect the size of the matrix when you read it ? If yes you can do something like that in initialize_grid :
void initialize_grid() {
ifstream input_file;
input_file.open("grid.txt");
int num;
if (input_file) {
// detect size
int size = 0;
string line;
if (!getline(input_file, line))
return;
istringstream iss(line);
while (iss >> num)
size += 1;
input_file.clear();
input_file.seekg(0);
for (int i = 0; i < size; ++i) {
vector<int> row; // game grid
vector<int> row2; // hidden grid
vector<int> row3; // guessed grid
for (int j = 0; j < size; ++j) {
if (input_file >> num)
row.push_back(num);
row2.push_back(-1);
row3.push_back(0);
}
game_grid.push_back(row);
hidden_grid.push_back(row2);
guessed.push_back(row3);
}
cout << "Get is ready, Challenger!" << endl << endl;
}
else {
cout << "Womp. File open failed!";
}
}
and else where you replace 6 by game_grid.size() (using size_t rather than int to type the indexes)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;
int e;
int f;
int aa = 0;
int bb = 0;
int cc = 0;
int dd = 0;
int ee = 0;
int ff = 0;
const string odd = "ODD";
const string even = "EVEN";
cout << "enter 6 numbers " << endl;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cin >> f;
aa = a % 2;
bb = b % 2;
cc = c % 2;
dd = d % 2;
ee = e % 2;
ff = f % 2;
if(aa == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
if(bb == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
if(cc == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
if(dd == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
if(ee == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
if(ff == 0){
cout << even << endl;
}else{
cout << odd << endl;
}
return 0;
}
for example is there a way to make it do the same thing but with less code, anything I should have included?
is there an easier way than having to write 6 if/else statements - is there a way to do all 6 in one statement or loop?
how could i improve its efficiency?
Write this function:
void outputEvenness(int n)
{
static const string odd = "ODD";
static const string even = "EVEN";
if(n % 2){
cout << odd<< endl;
} else {
cout << even << endl;
}
}
then call it using outputEvenness(a); outputEvenness(b); etc.
First of all you should include header <string>if you use class std::string.
Also there is no sense to define these strings when they are used as string literals. Also instead of different variables it would be better to define only one array. The auxiliary variables are also unnecessary.
If to assume that you may not use arrays then I would write the program the following way
#include <iostream>
#include <initializer_list>
int main()
{
const size_t N = 6;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
const char *odd = "ODD";
const char *even = "EVEN";
std::cout << "enter " << N << " numbers: ";
std::cin >> a >> b >> c >> d >> e >> f;
for ( int x : { a, b, c, d, e, f } )
{
if ( x % 2 == 0 )
{
std::cout << x << " is " << even << std::endl;
}
else
{
std::cout << x << " is " << odd << std::endl;
}
}
return 0;
}
If you are allowed to use arrays then the program could look as
#include <iostream>
int main()
{
const size_t N = 6;
int a[N] = {};
const char *odd = "ODD";
const char *even = "EVEN";
std::cout << "enter " << N << " numbers: ";
for ( int &x : a ) std::cin >> x;
for ( int x : a )
{
if ( x % 2 == 0 )
{
std::cout << x << " is " << even << std::endl;
}
else
{
std::cout << x << " is " << odd << std::endl;
}
}
return 0;
}
For this simple program there is no sense to define a separate function that will check whether a number is even or odd because it is this program that is such a function.:)
Use arrays and loops:
int a[6]; // Array of 6 ints
cout << "enter 6 numbers" << endl;
// Input the 6 numbers
for (int i = 0; i < 6; i++)
{
cin >> a[i];
}
// Output the results
for (int i = 0; i < 6; i++)
{
cout << a[i] << " is " << (a[i] & 1 ? "ODD" : "EVEN") << endl;
}
int value = 0;
string response = "";
cout << "enter 6 numbers " << endl;
for(int i=0; i<6; i++)
{
cin >> value;
value % 2 == 0 ? response+="even\n" : response+="odd\n";
}
cout << response;