Gå til innhold

har du en kode som ikke virker? post den her!


Anbefalte innlegg

Videoannonse
Annonse
Det blir enda mer plattform-avhengig også! :)

Prøv med cin.get();

cin.get() nei nei nei

 

int main(int argc, char* argv[])

{

for(;;) {

unsigned int w = rand() % 10;

for(unsigned int i = 0; i < w; i++)

  cout << " ";

  Sleep(10);

cout << "*";

}

eller

string a;
cin >> a;
for(;;) {
unsigned int w = rand() % 10;
for(unsigned int i = 0; i < w; i++)
 cout << " ";
 Sleep(10);
cout << a;

den er litt bedre

 

EDIT: Dette ble litt off :roll:

Endret av hotstian
Lenke til kommentar

Minner meg om noe jeg postet i fjor, under nicket 'daysleper':

 

#include <iostream>
#include <sstream>
#include <string>

#if defined(__linux__)
#include <unistd.h>
#define mySleep(x) usleep(static_cast<unsigned long>(x * 1000000))
#else
#include <windows.h>
#define mySleep(x) Sleep(static_cast<DWORD>(x * 1000))
#endif

using namespace std;


const double PAUSE = 0.2;
const unsigned int WIDTH = 79; // Adjust for a suitable width of your console. (151)
const char SYMBOL = '#';

// Rules are based on the 8 states:
// 1. 000
// 2. 001
// 3. 010
// 4. 011
// 5. 100
// 6. 101
// 7. 110
// 8. 111

/* 
 Here are some rules to try out:
 01011010 (90)
 00011110 (30)
 01101110 (110)
*/


bool chToBool(char ch)
{
if(ch == '0')
 return(false);
return(true);
} // chToBool


class CellularAutomata {
public:
CellularAutomata(long width_);
~CellularAutomata();
bool generate(bool prev1, bool prev2, bool prev3);
void draw(long steps); // 0 is unlimited steps
void rule(char const* rule_);
bool* prevLine;

private:
bool _rule[8];	
bool* nextLine;
}; // CellularAutomata



CellularAutomata::CellularAutomata(long width_)
{
prevLine = new bool[width_];
nextLine = new bool[width_];
} // constructor


CellularAutomata::~CellularAutomata()
{
delete(prevLine);
delete(nextLine);
} // destructor


bool CellularAutomata::generate(bool prev1, bool prev2, bool prev3)
{	
if(!prev1 && !prev2 && !prev3) // 1. 000
 return(_rule[0]);
else if(!prev1 && !prev2 && prev3) // 2. 001
 return(_rule[1]);
else if(!prev1 && prev2 && !prev3) // 3. 010
 return(_rule[2]);
else if(!prev1 && prev2 && prev3) // 4. 011
 return(_rule[3]);
else if(prev1 && !prev2 && !prev3) // 5. 100
 return(_rule[4]);
else if(prev1 && !prev2 && prev3) // 6. 101
 return(_rule[5]);
else if(prev1 && prev2 && !prev3) // 7. 110
 return(_rule[6]);
else if(prev1 && prev2 && prev3)  // 8. 111
 return(_rule[7]);	
return(0); // to get rid of the annoying warning :)
} // generate


void CellularAutomata::draw(long steps) // 0 is unlimited steps
{
// Draw the first line
for(unsigned int i = 0; i < WIDTH; i++) 
 if(prevLine[i])
 	cerr << SYMBOL;
 else
 	cerr << ' ';

cerr << endl;

long counter = 0;
bool* tempLine;

while(counter < steps || steps == 0) {

 // First column..
 if(nextLine[0] = generate(0, prevLine[0], prevLine[1]))
 	cerr << SYMBOL;
 else
 	cerr << ' ';  

 // ..the ones in between..
 for(unsigned int i = 1; i < WIDTH -1; i++) 
 	if(nextLine[i] = generate(prevLine[i-1], prevLine[i], prevLine[i+1]))
   cerr << SYMBOL;
 	else
   cerr << ' ';  
 
 // ..and the last column.
 if(nextLine[WIDTH] = generate(prevLine[WIDTH-1], prevLine[WIDTH], 0))
 	cerr << SYMBOL;
 else
 	cerr << ' ';    

 cerr << endl;
 
 tempLine = prevLine;
 prevLine = nextLine;
 nextLine = tempLine;
 
 counter++;
 
 mySleep(PAUSE);
} // while(...

} // drawLine


void CellularAutomata::rule(char const* rule_)
{
stringstream r;
r << rule_;
_rule[7] = chToBool(r.str()[0]);
_rule[6] = chToBool(r.str()[1]);
_rule[5] = chToBool(r.str()[2]);
_rule[4] = chToBool(r.str()[3]);
 _rule[3] = chToBool(r.str()[4]);
_rule[2] = chToBool(r.str()[5]);
_rule[1] = chToBool(r.str()[6]);
 _rule[0] = chToBool(r.str()[7]);	
} // rule



int main(int argc, char** argv)
{
CellularAutomata ca(WIDTH);


if(argc < 2) {
 cerr << "Please enter a rule, a rule is an 8-bit string of zeros and ones." << endl;
 return(1);
}
else {
 ca.rule(argv[1]);
}

// We "bootstrap" with one point at the top.
ca.prevLine[WIDTH / 2] = 1;
ca.prevLine[(WIDTH / 2) + 3] = 1;
ca.prevLine[(WIDTH / 2) - 3] = 1;

ca.draw(0);

return(0);
} // main

 

Koden er et himmla rot. Heh..

Endret av søppel
Lenke til kommentar

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int radone = 10;

      float maxdeg;
      float maxvol;
      float curdeg;
      float curvol;
      
float calculatecone(float x){

// Følgende linje gir beskjed om syntax error before ';' token
     float ans = (1/3 * pow( 1/( radone * (x/360)),2.0)* 3.14 * sqrt(pow(radone,2.0) - pow((1 / ( radone*x/360)),2.0));
     return ans;
     }

int main(int argc, char *argv[])
{
   degvol maxcone = new degvol;
   
// Følgende linje gir beskjed om syntax error before ';' token
   for(float d = 0.0; d < 360.0; d = d + 0.1;){
             curdeg = d;
             curvol = calculatecone(x);
             if (curdeg > maxdeg){
                maxdeg = curdeg;
                maxvol = curvol;

                cout<<maxdeg;
                cout<<" gives a volume of ";
                cout<<maxvol;
                cout<<"\n";
                }
             }
   system("PAUSE");
   return EXIT_SUCCESS;
}

 

Jeg har satt en kommentar på linja før syntax error på begge stedene kompileren misliker..

(Lenge siden jeg har drevet med c++, ser jeg :ohmy: )

 

Det ser ut til at den gir flere errors jo fler jeg retter =/

 

Hvis du har lyst til å rette på formelen jeg bruker, kan du få sjansen i denne tråden:

http://forum.hardware.no/index.php?s=&act=...82&t=350353&st=

Endret av Zethyr
Lenke til kommentar

Oppdatert kode:

 

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;
      
float calculatecone(float x){
     float radone = 10.0;
//V = 1/3 * (PI) * (R1² - (R1 * (1/(2PI/(PIx/90)))) * (R1*(1/(2PI/(PIx/90)))
     float ans = (1/3 * 3,14 * (pow(radone,2.0) - pow((radone * (1/(2*3,14/(3,14*x/90)))),2.0));
     return ans;
     }

int main(int argc, char *argv[])
{
   
      float maxdeg = 0.0;
      float maxvol = 0.0;
      float curdeg;
      float curvol;
   
   for(float d = 0.0; d < 360.0; d = d + 0.1){
             curdeg = d;
             curvol = calculatecone(d);
             if (curdeg > maxdeg){
                maxdeg = curdeg;
                maxvol = curvol;
                cout<<maxdeg;
                cout<<" gives a volume of ";
                cout<<maxvol;
                cout<<"\n";
                }
             }
   system("PAUSE");
   return EXIT_SUCCESS;
}

 

10 ISO C++ says that `double pow(double, double)' and `float std::pow(float, float)' are ambiguous even though the worst conversion for ...

 

10 syntax error before `;' token

 

25 D:\Program Files\Dev-Cpp\Projects\cone-maximizing-osix\cone.cpp `maxdeg' undeclared (first use this function)

Lenke til kommentar

/* hva er feil her

jeg finner ikke feilen

*/

 

 

#include <time.h>

#include "stdafx.h"

#include <iostream>

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

srand(time(0));

int a = rand ()%20;

int b = rand ()%7;

 

cout<<a<<"+"<<b<<endl;

 

int c;

cin >>c;

int d;

int e;

 

d = a + b;

cerr;

e = d;

 

if (c == e)

{

cout<<"riktig"<<endl;

}

else

{

cout<<"feil"<<endl;

}

 

 

 

 

 

 

return 0;

}

Endret av glad
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...