Jump to content
JohnyCNAM

Urgent ajutor...c++

Recommended Posts

Verifici si tu eventualele erori de tastare pentru ca il scriu direct aici.


#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using std:ifstream;
using std::ofstream;
using std::endl;
using std::cin;
using std::cout;
using std::getline;
using std::string;

int main(int argv, char* argv[])
{
ifstream fIn;
ofstream fOut;
int n;
fIn.open(data.in);
fOut.open(data.out);
cout << "Cate numere doriti sa cititi ?\n";
cin >> n;
int counter = 0; // va tine numarul de numere pare;
int suma = 0; //va tine suma numerelor pare
if(fIn.is_open() && fOut.is_open())
{
for(unsigned int i = 0; i <= n;i++)
{
if(fIn.good())
{
string linie;
int temp = 0;
getline(fIn, linie);
temp = atoi(linie.c_str());
if((temp % 2) == 0)
{
counter++;
suma += temp;
}
}
}
int medie = suma / counter;
fout << medie;
fIn.close();
fOut.close();
return 0;
}

Edited by nedo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...