<C++> Gra konsolowa i błąd

0

Witam was. Mam pewien problem, z którym nie rada sobie poradzić. Najpierw Zachęcam do zerknięcia w kod.:

// Program Zgadywanka.cpp : Defines the entry point for the console application.
// Includes Start
#include <Windows.h>
#include <conio.h>
#include <vector>
#include <time.h>
#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <math.h>
 //Includes end
 // time definition
#define TIME = 60; //TIME = 60
bool clockgame();
using namespace std;//namespace declaration.

int main()//Funkcja główna
{ // main open.
	Beep(50, 100); //1
	Beep(50, 200); //2
	Beep(50, 300); //3
	Beep(50, 100); //1
	Beep(50, 200); //2
	Beep(50, 300); //3
	Beep(50, 400); //4
	Beep(50, 500); //5
	cout<<"    Chosse Spider     "<<endl; // output
	cout<<"You must chosse number, when time up, you lose."<<endl; // output
	cout<<"Clock Start!"<<endl;
	clockgame();
	getch(); //"WAIT" for press any key.
	return 0;//returns value 0
} // main close
bool clockgame() //second function
{ //bool open
	srand(time(NULL));
	int pozostalo = TIME; //this is a declaration of time.
	int i = 18; //declatation of "I"
	int chosse =(rand() %1000) + 1; //random "sECRET" Number.
	do //while
	{
		pozostalo--; //Time deleting :)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting x)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting xD
		pozostalo--; //Time deleting :)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting x)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting xD
		cout<<"You have only"<<pozostalo<<"Seconds! \n"; //output
		cout<<"Give me number :)"<<endl;
		int zgaduj; 
		cin >> zgaduj; 
		if(zgaduj == chosse) 
		{ 
			cout<<"Good! You retard"<<i<<"Points! \n";
			ostream hajne;
			hajne.open("score.dat" ios::binary | ios::in | ios::out);
			int glue;
			hajne >> glue;
			int zapis = glue + i;
			hajne << zapis;
			cout<<"Very good!"<<endl;
		} 
		if(zgaduj > chosse)
		{
			cout<<"Type smaller number!"<<endl;
		}
		 
		if(zgaduj < chosse)
		{
			cout<<"Type bigger number!"<<endl;
		}
	} 
	while(pozostalo >= 1); 
	if(pozostalo = 0)
		{
			cout<<"You Lose..."<<"You lose"<<i<<"Points."<<endl;
			ostream plik;//Files Stream
			plik.open("score.dat" ios::binary | ios::in | ios::out); //Save Binary
			int a;  
			plik >> a; //:O
			if(a = 0) // "IF" a = 0  
			{  
				cout<<"You don't have points!"<<endl; 
			}
			if(a > 0) // "IF" a > 0
			{
				cout<<"You have"<<a<<"Points,"<<"You lose"<<i<<"Points, and you have"<<a-i<<"Points."<<endl; //ostream
				int begin = a - i; //save this :))
				plik << begin; //they're don't cheat me! 
				time_t sekundy; 
				sekundy = time( NULL ); // time functions 
				plik << sekundy; //save the acctualy time to file. 
			} 
		} 
	return TRUE; //returns value TRUE 
} //bool close 

A teraz w logi:
template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)

0
marekszuwarek napisał(a):

Witam was. Mam pewien problem, z którym nie rada sobie poradzić. Najpierw Zachęcam do zerknięcia w kod.:

// Program Zgadywanka.cpp : Defines the entry point for the console application.
// Includes Start
#include <Windows.h>
#include <conio.h>
#include <vector>
#include <time.h>
#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <math.h>
 //Includes end
 // time definition
#define TIME = 60; //TIME = 60
bool clockgame();
using namespace std;//namespace declaration.

int main()//Funkcja główna
{ // main open.
	Beep(50, 100); //1
	Beep(50, 200); //2
	Beep(50, 300); //3
	Beep(50, 100); //1
	Beep(50, 200); //2
	Beep(50, 300); //3
	Beep(50, 400); //4
	Beep(50, 500); //5
	cout<<"    Chosse Spider     "<<endl; // output
	cout<<"You must chosse number, when time up, you lose."<<endl; // output
	cout<<"Clock Start!"<<endl;
	clockgame();
	getch(); //"WAIT" for press any key.
	return 0;//returns value 0
} // main close
bool clockgame() //second function
{ //bool open
	srand(time(NULL));
	int pozostalo = TIME; //this is a declaration of time.
	int i = 18; //declatation of "I"
	int chosse =(rand() %1000) + 1; //random "sECRET" Number.
	do //while
	{
		pozostalo--; //Time deleting :)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting x)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting xD
		pozostalo--; //Time deleting :)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting x)
		pozostalo--; //Time deleting :D
		pozostalo--; //Time deleting xD
		cout<<"You have only"<<pozostalo<<"Seconds! \n"; //output
		cout<<"Give me number :)"<<endl;
		int zgaduj; 
		cin >> zgaduj; 
		if(zgaduj == chosse) 
		{ 
			cout<<"Good! You retard"<<i<<"Points! \n";
			ostream hajne;
			hajne.open("score.dat" ios::binary | ios::in | ios::out);
			int glue;
			hajne >> glue;
			int zapis = glue + i;
			hajne << zapis;
			cout<<"Very good!"<<endl;
		} 
		if(zgaduj > chosse)
		{
			cout<<"Type smaller number!"<<endl;
		}
		 
		if(zgaduj < chosse)
		{
			cout<<"Type bigger number!"<<endl;
		}
	} 
	while(pozostalo >= 1); 
	if(pozostalo = 0)
		{
			cout<<"You Lose..."<<"You lose"<<i<<"Points."<<endl;
			ostream plik;//Files Stream
			plik.open("score.dat" ios::binary | ios::in | ios::out); //Save Binary
			int a;  
			plik >> a; //:O
			if(a = 0) // "IF" a = 0  
			{  
				cout<<"You don't have points!"<<endl; 
			}
			if(a > 0) // "IF" a > 0
			{
				cout<<"You have"<<a<<"Points,"<<"You lose"<<i<<"Points, and you have"<<a-i<<"Points."<<endl; //ostream
				int begin = a - i; //save this :))
				plik << begin; //they're don't cheat me! 
				time_t sekundy; 
				sekundy = time( NULL ); // time functions 
				plik << sekundy; //save the acctualy time to file. 
			} 
		} 
	return TRUE; //returns value TRUE 
} //bool close 

A teraz w logi:template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)

Chyba logów nie podałeś xD

1
        pozostalo--; //Time deleting :)
        pozostalo--; //Time deleting :D
        pozostalo--; //Time deleting x)
        pozostalo--; //Time deleting :D
        pozostalo--; //Time deleting xD
        pozostalo--; //Time deleting :)
        pozostalo--; //Time deleting :D
        pozostalo--; //Time deleting x)
        pozostalo--; //Time deleting :D
        pozostalo--; //Time deleting xD

Rozumiem ze odjęcie 10 było zbyt mainstreamowe? o_O

cout<<"Good! You retard"<<i<<"Points! \n";

Ktoś zgadł a ty go przezywasz od "opóźnionego w rozwoju"? Czemu? :(

if(pozostalo = 0)

= to przypisanie a nie porównanie (porównanie to ==), zresztą ten warunek jest zupełnie zbędny bo po wyjściu z pętli wiadomo ile ta zmienna wynosi...
Analogicznie masz błędnie zrobione inne porównania.

return TRUE; //returns value TRUE

Zwrócenie tego z main() oznacza że mówisz systemowi operacyjnemu że program wysypał się z błędem. Poprawne wykonanie programu sygnalizowane jest przez zwrócenie 0.

A co do błędu kompilacji:

            ostream hajne;
            hajne.open("score.dat" ios::binary | ios::in | ios::out);
            int glue;
            hajne >> glue;

ostream = output stream = strumień wyjściowy
Nie ma znaczenia że otwarłeś plik w trybie ios::in bo i tak patrzysz na niego przez pryzmat strumienia wyjściowego. To tak jakbyś miał ekspres do kawy na który założyłeś plastikowy klosz, tak że widać tylko guzik do robienia "espresso". Mimo że ekspres jako taki może robić też inne rodzaje kawy, ty możesz zrobić tylko espresso bo inne guziki są zasłonięte.
Podsumowując: jeśli chcesz zarówno pisać jak i czytać z tego pliku to musisz go otworzyć jako fstream

1 użytkowników online, w tym zalogowanych: 0, gości: 1