Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Тест-форум (http://forum.oszone.net/forumdisplay.php?f=26)
-   -   [решено] Помогите разобраться (http://forum.oszone.net/showthread.php?t=222587)

Obscurus64 10-12-2011 16:46 1812759

Помогите разобраться
 
Доброго времени суток. Вообщем есть простенькая задачка в которой я не могу разобраться =/
Во входном файле input.txt записываются через пробел 3 числа, если сумма двух первых равняется третьему, то в файл output.txt выводится "+", если же произведение первых двух равно третьему , то выводится "*". Весь алгоритм условий вобщем то понятен, как правильно организовать ввод-вывод?

Вот нароботки:
Код:

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

using namespace std;   

int main () {
  int a, b, c, x, y;
  string s;
  ifstream in;
  in.open("input.txt");
  getline(in, s);
  in.close();
  a=s[0];
  b=s[2];
  c=s[4];
  ofstream out;
  out.open("output.txt");
  if (c==a+b) out << "+";
    else if (c==a*b) out << "*";
      else out << "";
  out.close();
return 0;
}


ferget 11-12-2011 22:06 1813472

Код:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main () {
  int a, b, c, x, y;

  ifstream in;
  in.open("input.txt");
  in>>a>>b>>c;
  in.close();
 
  ofstream out;
  out.open("output.txt");

  if (c==a+b) out << "+";
    else if (c==a*b) out << "*";
      else out << "";
         
  out.close();
return 0;
}


Obscurus64 12-12-2011 18:00 1813868

Огромное спасибо)


Время: 18:25.

Время: 18:25.
© OSzone.net 2001-