Forum: Konstigt Fel

Forum huvudsida -> Programmering -> Konstigt Fel

Sidor: 1

Till botten

martin310 22:00 - 28:e November 2008 | Post #1
Medlem
Inlägg: 132


Skicka PM
Har problem med den här koden det ser ut somom den skulle fungera bra men det gör den inte!

  1. #include <iostream>
  2. #include <ctime>
  3. #include <windows.h>
  4.  
  5. using std::cout;
  6. using std::cin;
  7. using std::string;
  8. using std::srand;
  9. using std::rand;
  10.  
  11. int main()
  12. {
  13. srand(time(NULL));
  14.  
  15. string what;
  16. string how;
  17. int slump;
  18. int times;
  19.  
  20. cout << "What do you want to do? ";
  21. cin >> what;
  22.  
  23. cout << "nnWhat do you do it in (times, how much, etc)? ";
  24. cin >> how;
  25.  
  26. cout << "Press enter as fast as possible!!!!";
  27.  
  28. while(1)
  29. {
  30. cin.get();
  31. slump = rand() % 14 + 1
  32.  
  33. if(slump == "1");
  34. {
  35. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
  36. }
  37. else if(slump == "2");
  38. {
  39. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
  40. }
  41. else if(slump == "3");
  42. {
  43. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE);
  44. }
  45. else if(slump == "4");
  46. {
  47. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
  48. }
  49. else if(slump == "5");
  50. {
  51. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  52. }
  53. else if(slump == "6");
  54. {
  55. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
  56. }
  57. else if(slump == "7");
  58. {
  59. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  60. }
  61. else if(slump == "8");
  62. {
  63. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN);
  64. }
  65. else if(slump == "9");
  66. {
  67. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE);
  68. }
  69. else if(slump == "10");
  70. {
  71. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE);
  72. }
  73. else if(slump == "11");
  74. {
  75. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
  76. }
  77. else if(slump == "12");
  78. {
  79. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  80. }
  81. else if(slump == "13");
  82. {
  83. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  84. }
  85. else if(slump == "14");
  86. {
  87. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  88. }
  89.  
  90. times = times + 1;
  91. cout <<times<< " " <<how;
  92. cout << "nYou does: " <<what;
  93. }
  94. return 0;
  95. }


Fel filen:
  1. 1>------ Build started: Project: do anything, Configuration: Debug Win32 ------
  2. 1>Compiling...
  3. 1>main.cpp
  4. 1>c:usersfam. risell-liljadocumentsvisual studio 2008projectschangerchangermain.cpp(13) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
  5. 1>c:usersfam. risell-liljadocumentsvisual studio 2008projectschangerchangermain.cpp(21) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
  6. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)' [found using argument-dependent lookup]
  7. 1> with
  8. 1> [
  9. 1> _Elem=char,
  10. 1> _Traits=std::char_traits<char>
  11. 1> ]
  12. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(1146): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)' [found using argument-dependent lookup]
  13. 1> with
  14. 1> [
  15. 1> _Elem=char,
  16. 1> _Traits=std::char_traits<char>
  17. 1> ]
  18. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(1148): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)' [found using argument-dependent lookup]
  19. 1> with
  20. 1> [
  21. 1> _Elem=char,
  22. 1> _Traits=std::char_traits<char>
  23. 1> ]
  24. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(1150): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)' [found using argument-dependent lookup]
  25. 1> with
  26. 1> [
  27. 1> _Elem=char,
  28. 1> _Traits=std::char_traits<char>
  29. 1> ]
  30. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
  31. 1> with
  32. 1> [
  33. 1> _Elem=char,
  34. 1> _Traits=std::char_traits<char>
  35. 1> ]
  36. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
  37. 1> with
  38. 1> [
  39. 1> _Elem=char,
  40. 1> _Traits=std::char_traits<char>
  41. 1> ]
  42. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
  43. 1> with
  44. 1> [
  45. 1> _Elem=char,
  46. 1> _Traits=std::char_traits<char>
  47. 1> ]
  48. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
  49. 1> with
  50. 1> [
  51. 1> _Elem=char,
  52. 1> _Traits=std::char_traits<char>
  53. 1> ]
  54. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
  55. 1> with
  56. 1> [
  57. 1> _Elem=char,
  58. 1> _Traits=std::char_traits<char>
  59. 1> ]
  60. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
  61. 1> with
  62. 1> [
  63. 1> _Elem=char,
  64. 1> _Traits=std::char_traits<char>
  65. 1> ]
  66. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
  67. 1> with
  68. 1> [
  69. 1> _Elem=char,
  70. 1> _Traits=std::char_traits<char>
  71. 1> ]
  72. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
  73. 1> with
  74. 1> [
  75. 1> _Elem=char,
  76. 1> _Traits=std::char_traits<char>
  77. 1> ]
  78. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
  79. 1> with
  80. 1> [
  81. 1> _Elem=char,
  82. 1> _Traits=std::char_traits<char>
  83. 1> ]
  84. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
  85. 1> with
  86. 1> [
  87. 1> _Elem=char,
  88. 1> _Traits=std::char_traits<char>
  89. 1> ]
  90. 1> c:program filesmicrosoft visual studio 9.0vcincludeistream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
  91. 1> with
  92. 1> [
  93. Granola, det är gratis och funkar på både Windows och Linux, och försämrar inte datorns prestandad!





Nissebosselasse 10:32 - 29:e November 2008 | Post #2
Medlem
Inlägg: 490


Skicka PM
Lägg in en #include <string>. längst upp.

-------------------------
http://pushingcows.se
Gula Nallen



martin310 11:24 - 29:e November 2008 | Post #3
Medlem
Inlägg: 132


Skicka PM
Jag blev av med några fel men det är en dröse kvar:

  1. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(14) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
  2. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(34) : error C2446: '==' : no conversion from 'const char *' to 'int'
  3. 1> There is no context in which this conversion is possible
  4. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(34) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  5. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(38) : error C2446: '==' : no conversion from 'const char *' to 'int'
  6. 1> There is no context in which this conversion is possible
  7. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(38) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  8. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(42) : error C2446: '==' : no conversion from 'const char *' to 'int'
  9. 1> There is no context in which this conversion is possible
  10. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(42) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  11. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(46) : error C2446: '==' : no conversion from 'const char *' to 'int'
  12. 1> There is no context in which this conversion is possible
  13. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(46) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  14. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(50) : error C2446: '==' : no conversion from 'const char *' to 'int'
  15. 1> There is no context in which this conversion is possible
  16. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(50) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  17. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(54) : error C2446: '==' : no conversion from 'const char *' to 'int'
  18. 1> There is no context in which this conversion is possible
  19. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(54) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  20. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(58) : error C2446: '==' : no conversion from 'const char *' to 'int'
  21. 1> There is no context in which this conversion is possible
  22. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(58) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  23. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(62) : error C2446: '==' : no conversion from 'const char *' to 'int'
  24. 1> There is no context in which this conversion is possible
  25. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(62) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  26. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(66) : error C2446: '==' : no conversion from 'const char *' to 'int'
  27. 1> There is no context in which this conversion is possible
  28. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(66) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
  29. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(70) : error C2446: '==' : no conversion from 'const char *' to 'int'
  30. 1> There is no context in which this conversion is possible
  31. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(70) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]'
  32. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(74) : error C2446: '==' : no conversion from 'const char *' to 'int'
  33. 1> There is no context in which this conversion is possible
  34. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(74) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]'
  35. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(78) : error C2446: '==' : no conversion from 'const char *' to 'int'
  36. 1> There is no context in which this conversion is possible
  37. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(78) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]'
  38. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(82) : error C2446: '==' : no conversion from 'const char *' to 'int'
  39. 1> There is no context in which this conversion is possible
  40. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(82) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]'
  41. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(86) : error C2446: '==' : no conversion from 'const char *' to 'int'
  42. 1> There is no context in which this conversion is possible
  43. 1>c:\users\fam. risell-lilja\documents\visual studio 2008\projects\changer\changer\main.cpp(86) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]'


-------------------------

Hjälp jorden med Granola, det är gratis och funkar på både Windows och Linux, och försämrar inte datorns prestandad!



Senast redigerad 11:29 - 29:e November 2008


Nissebosselasse 13:23 - 29:e November 2008 | Post #4
Medlem
Inlägg: 490


Skicka PM
slump är definierad som ett heltal, och därmed kan du inte jämföra det med en strängtyp (slump == "1"). Gör om slump till en sträng, eller jämför med heltal istället.

-------------------------
http://pushingcows.se
Gula Nallen



MikeNeuhaus 15:21 - 29:e November 2008 | Post #5
Medlem
Inlägg: 14


Skicka PM
Du kan ju börja att lägga upp den på pastebin så att man ser hela din kod och inte sidan får krupp...Smiley




martin310 19:14 - 29:e November 2008 | Post #6
Medlem
Inlägg: 132


Skicka PM
Tack det funkar nu!

-------------------------

Hjälp jorden med Granola, det är gratis och funkar på både Windows och Linux, och försämrar inte datorns prestandad!





Sidor: 1

Forum huvudsida -> Programmering -> Konstigt Fel
Atom feed

Du får inte posta i den här tråden | Till toppen