Hello! Newbie in C++ needs help!
I have to write a program, that counts how many times do these symbols (==, !=, <=, >=) repeat in .txt document. So I wrote a code, but it calculates wrong, and I can`t find a mistake,...please help!
#include <conio.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
cout<<"Program counts how many times repeats == != <= >= in data.txt document "<<endl;
char ch;
int sk1,sk2,sk3,sk4;
sk1=sk2=sk3=sk4=0;
ifstream file("data.txt");
if(!file)
{
cout<<"File not found!";
}
else
{
while(!file.eof())
{
//==
file.get(ch);
if(ch=='=')
{
file.get(ch);
if(ch=='=');
sk1++;
}
//!=
else if(ch=='!')
{
file.get(ch);
if(ch=='=');
sk2++;
}
//<=
else if(ch=='<')
{
file.get(ch);
if(ch=='=');
sk3++;
}
//>=
else if(ch=='>')
{
file.get(ch);
if(ch=='=');
sk4++;
}
}
cout<<endl;
cout<<"Symbols '==' repeat "<<sk1<<" times!"<<endl;
cout<<"Symbols '!=' repeat "<<sk2<<" times!"<<endl;
cout<<"Symbols '<=' repeat "<<sk3<<" times!"<<endl;
cout<<"Symbols '>=' repeat "<<sk4<<" times!"<<endl;
}
file.close();
getch();
return 0;
}
Thank you!
I have to write a program, that counts how many times do these symbols (==, !=, <=, >=) repeat in .txt document. So I wrote a code, but it calculates wrong, and I can`t find a mistake,...please help!
#include <conio.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
cout<<"Program counts how many times repeats == != <= >= in data.txt document "<<endl;
char ch;
int sk1,sk2,sk3,sk4;
sk1=sk2=sk3=sk4=0;
ifstream file("data.txt");
if(!file)
{
cout<<"File not found!";
}
else
{
while(!file.eof())
{
//==
file.get(ch);
if(ch=='=')
{
file.get(ch);
if(ch=='=');
sk1++;
}
//!=
else if(ch=='!')
{
file.get(ch);
if(ch=='=');
sk2++;
}
//<=
else if(ch=='<')
{
file.get(ch);
if(ch=='=');
sk3++;
}
//>=
else if(ch=='>')
{
file.get(ch);
if(ch=='=');
sk4++;
}
}
cout<<endl;
cout<<"Symbols '==' repeat "<<sk1<<" times!"<<endl;
cout<<"Symbols '!=' repeat "<<sk2<<" times!"<<endl;
cout<<"Symbols '<=' repeat "<<sk3<<" times!"<<endl;
cout<<"Symbols '>=' repeat "<<sk4<<" times!"<<endl;
}
file.close();
getch();
return 0;
}
Thank you!