[c++].exe só corre no meu pc

XeniX

Power Member
Boas!
Fiz um programa em c++.
Depois de feito o programa, eu fui à pasta do projecto e criei um arquivo .rar com o .exe do programa para enviar pelo messenger a amigos.
O problema é que eles não conseguem executar o programa. Mas no meu pc funciona!
É capaz de ser uma questão trivial, mas já googlei e não encontrei nada.

Se precisarem do código:
Código:
#include <iostream>
#include <time.h>

using namespace std;

/*************************
*       Guideline        *
*                        *
*  for this game we will *
* use this set of numbers*
* a=7     b=9    c=3     *
*   the result is 21     *
*************************/


int main()
{
char chooseYN;
int a;
int b;
int c;

int CodeNumber=(a*b)/c;
    
time_t start_time, cur_time;
time(&start_time);


    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<"Please insert the secret code:";
    cout<<"**"<<endl;
    cout<<endl;
    cout<<"Hi! I guess it's your first time here! (press enter to proceed)"<<endl;

    cin.get();
    
    cout<<"Can you discover the secret code of this program, and unveil the secret information it contains? (type 'y' or 'n' to proceed)"<<endl;
    
    cin>>chooseYN;
    
    if(chooseYN=='y'||chooseYN=='Y') {
                    cout<<"Ok! Let's proceed then! (press enter to proceed)"<<endl;
                    
                    cin.get();
                    
                    cout<<"To find this code you'll need to be aware of the rules:"<<endl;
                    cin.get();
                    cout<<"\t1-The code is composed by a positive integer number of 2 algarisms"<<endl;
                    cin.get();
                    cout<<"\t2-The code number is the result of the product of two numbers (a,b) divided by a third (c)"<<endl;
                    cin.get();
                    cout<<"\t3-Numbers 'a', 'b' and 'c' are constituted by one algarism, different than zero,\l and smaller than 10"<<endl;
                    cin.get();
                    cout<<"\t4-The code number is odd"<<endl;
                    cin.get();
                    
                    cout<<"This is it! Press enter when you feel ready!"<<endl;
                    cin.get();
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
    
                    cout<<"Please insert the secret code:"<<endl;
                    cout<<"Step 1: insert 'a':";
                    
                    cin>>a;
                    
                    cout<<endl<<"Step 1: insert 'b':";
                    
                    cin>>b;
                    
                    cout<<endl<<"Step 1: insert 'c':";
                    
                    cin>>c;
                    
                    if (CodeNumber!=21) {
                                        
                                cout<<"Analysing information... Pease wait..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                
                                cout<<"Verifying constant 'a'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'b'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'c'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Computing..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 4);      
                                        
                                cout<<"Access denied"<<endl;
                                
                                return 0;
                                
                                }
                    
                    else if (CodeNumber==21) {
                                
                                cout<<"Analysing information... Pease wait..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                
                                cout<<"Verifying constant 'a'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'b'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'c'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Computing..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 4);
                                cout<<"Access granted"<<endl;
                                
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<"***************************************"<<endl;
                                cout<<"*         N.       S.       A.        *"<<endl;
                                cout<<"*    National    Security    Agency   *"<<endl;
                                cout<<"***************************************"<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<"You've been fooled! Sorry! :P Press enter to exit this bloody program";
                                cin.get();
                                
                                return 0;
                                
                                }
      else {
           return 0;
           }
}}


Já agora: se me explicassem a função agradecia. Copiei-a da net mas não a percebo na totalidade :) :
Código:
time_t start_time, cur_time;
time(&start_time);

do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);

Agradecimentos avançados!!
 
Primeiro deixa-me sugerir que melhores esse código. Tens aí bastante código repetido que podia estar num função separada.

O que acontece ao tentar correr o programa noutro PC?
 
Já agora: se me explicassem a função agradecia. Copiei-a da net mas não a percebo na totalidade :) :
Código:
time_t start_time, cur_time;
time(&start_time);

do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
Agradecimentos avançados!!
Esse código fica no while durante 1 segundo.
 
Qual o Sistema Operativo que estas a usar??
Qual o compilador que estas a usar??
Qual o Sistema Operativo dos teus amigos??
Estás a enviar-lhes versão de debug ou de release??
Com este tipo de informação é mais fácil tentar resolver-te o problema
 
Qual o Sistema Operativo que estas a usar??
1-Qual o compilador que estas a usar??
2-Qual o Sistema Operativo dos teus amigos??
3-Estás a enviar-lhes versão de debug ou de release??
Com este tipo de informação é mais fácil tentar resolver-te o problema

1- Devcpp
2-Windows xp
3- estou a enviar-lhes este fixeiro: "C:\Dev-Cpp\projects\project2.exe"

Obrigado a todos pelas observações. Eu sei que o código está ranhoso, mas estou ainda a aprrender, e ainda não comecei com as classes e isso...
Também ainda não testei exaustivamente o programa, vou hoje tentar melhorá-lo.

anyway, o que eu gostava de saber é como posso, com o devcpp, exportar o programa .exe de modo a que corresse noutro pc. É que nem os "hello world" correm!


Obrigado por tudo!
 
Eu tenho XP SP2, compilo e executo o programa sem problemas deu-me um erro por causa de um escape code mas depois de corrigido corre na boa foi esta a linha que alterei
Código:
cout<<"\t3-Numbers 'a', 'b' and 'c' are constituted by one algarism, different than zero,\l and smaller than 10"<<endl;
cout<<"\t3-Numbers 'a', 'b' and 'c' are constituted by one algarism, different than zero, and smaller than 10"<<endl;

O teu windows XP é de 32Bits Certo?
 
Problema #1 : Expressao aritmética usando variáveis não inicializadas.
Logo nas primeiras linhas
Código:
char chooseYN;
int a;
int b;
int c;

int CodeNumber=(a*b)/c;
as vars a,b e c têm lixo (pode ser qualquer valor, até zero!, mas não necessariamente), e ao tentar-se dividir por 'c' gera-se uma falta (que aqui no vista aparece logo "program stopped working" dialog ..)

Eu atribuí um valor qualquer a CodeNumber, (por ex, CodeNumber = 32242) e como ja nao se poe o problema anterior, a coisa "funciona" (compile+exec)

Ai está um erro...mas ao ver o código assim não vai fazer o k é pretendido...eu penso k o k keres fazer tens k por a formula do codenumber no fim dos cin's, ou seja lg a seguir a:
cin>> c;


Cumps:D
 
Aleluia! Sinto-me maior que deus!

Consegui finalmente colocar o programa a fuceminar!!
Aqui está o código:

Código:
#include <iostream>
#include <time.h>

using namespace std;

/*************************
*       Guideline        *
*                        *
*  for this game we will *
* use this set of numbers*
* a=7     b=9    c=3     *
*   the result is 21     *
*************************/


int main()
{
char chooseYN;
int a;
int b;
int c;

    
time_t start_time, cur_time;
time(&start_time);


    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<" "<<endl;
    cout<<"Please insert the secret code:";
    cout<<"**"<<endl;
    cout<<endl;
    cout<<"Hi! I guess it's your first time here! (press enter to proceed)"<<endl;

    cin.get();
    
    cout<<"Can you discover the secret code of this program, and unveil the secret information it contains? (type 'y' or 'n' to proceed)"<<endl;
    
    cin>>chooseYN;
    
    if(chooseYN=='y'||chooseYN=='Y') {
                    cout<<"Ok! Let's proceed then! (press enter to proceed)"<<endl;
                    
                    cin.get();
                    
                    cout<<"To find this code you'll need to be aware of the rules:"<<endl;
                    cin.get();
                    cout<<"\t1-The code is composed by a positive integer number of 2 algarisms"<<endl;
                    cin.get();
                    cout<<"\t2-The code number is the result of the product of two numbers (a,b) divided by a third (c)"<<endl;
                    cin.get();
                    cout<<"\t3-Numbers 'a', 'b' and 'c' are constituted by one algarism, different than zero, and smaller than 10"<<endl;
                    cin.get();
                    cout<<"\t4-The code number is odd"<<endl;
                    cin.get();
                    
                    cout<<"This is it! Press enter when you feel ready!"<<endl;
                    cin.get();
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
                        cout<<" "<<endl;
    
                    cout<<"Please insert the secret code:"<<endl;
                    cout<<"Step 1: insert 'a':";
                    
                    cin>>a;
                    
                    cout<<endl<<"Step 1: insert 'b':";
                    
                    cin>>b;
                    
                    cout<<endl<<"Step 1: insert 'c':";
                    
                    cin>>c;
                  
                    int multiplication=a*b;
                    int division=multiplication/c;
                    int CodeNumber=division;
                    
                    if (CodeNumber != 21) {
                                        
                                cout<<"Analysing information... Pease wait..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                
                                cout<<"Verifying constant 'a'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'b'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'c'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Computing..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 4);      
                                        
                                cout<<"Access denied"<<endl;
                                
                                system("pause");
                                
                                return 0;
                                
                                }
                    
                    else if (CodeNumber == 21) {
                                
                                cout<<"Analysing information... Pease wait..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                
                                cout<<"Verifying constant 'a'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'b'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Verifying constant 'c'"<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 1);
                                cout<<"Computing..."<<endl;
                                do {
                                     time(&cur_time);
                                     }
                                while((cur_time - start_time) < 4);
                                cout<<"Access granted"<<endl;
                                
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<"***************************************"<<endl;
                                cout<<"*         N.       S.       A.        *"<<endl;
                                cout<<"*    National    Security    Agency   *"<<endl;
                                cout<<"***************************************"<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<endl;
                                cout<<"You've been fooled! Sorry! :P Press enter to exit this bloody program";
                                system("pause");
                                
                                return 0;
                                
                                }
                                }
      else if (chooseYN=='n'||chooseYN=='N') {
                 
           system("pause");
           
           return 0;
           }
           
}

O que eu fiz:
-Segui o conselho do migp999
-Substituí todos os cin.get() po system("pause"). Ao que parece o devcpp tem uns problemas com os cin.get() http://www.programmersheaven.com/mb/beginnercpp/360448/360448/ReadMessage.aspx

Agora só falta ir "kitando" o programa á medida que aprenda mais.

Obrigado a todos! E cuidado a quem usar como eu o devcpp.

Se possível ainda hoje vou ver se o executável do programa finciona noutros computadores.
 
Back
Topo