| View previous topic :: View next topic |
| Author |
Message |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Fri Dec 14, 2007 8:35 am Post subject: where's the error?!?[C++] |
|
|
i can't find it... it says the error is on line 40 (when i finish with return0)
sorry for spargetti (goto-ed) code
can someone fix the error?
| Code: |
//something interactive...
//by teh 1338 nub zzoozz
#include <iostream.h>
int main()
{
int choice;
Jump1:
{
while (choice < 50000)
{
cout << "Insert a number";
cout << "from 1 to 5";
cout << ", 0 to quit";
cin >> choice;
switch (choice)
{
case 1:cout <<"Pfft, 1..." << endl;
case 2:cout <<"OoOo, 1+1=2!" << endl;
case 3:cout <<"O RLY? 3?!?" << endl;
case 4:cout <<"Mamamia! itsa 4!" << endl;
case 5:cout <<"Last owns all!" << endl;
case 0:goto Jump3;
default:goto Jump2;
}
Jump2:
{
cout <<"Too high!" << endl;
goto Jump1;
}
Jump3:
{
cout <<"Ok, bye!" << endl;
system("pause");
return 0;
}
}
}
return 0}
|
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 14, 2007 10:43 am Post subject: |
|
|
| The problem is that you have a whole lot of brackets that you don't need.
|
|
| Back to top |
|
 |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Fri Dec 14, 2007 10:48 am Post subject: |
|
|
| Flyte wrote: | | The problem is that you have a whole lot of brackets that you don't need. |
no, the error isnt there,i fixed like 4 errors adding brackets at the end
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Dec 14, 2007 10:55 am Post subject: |
|
|
| Missing ; after return 0. You've to do a lot to improve your code. I have to say that your code is f'ugly.
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 14, 2007 11:02 am Post subject: Re: where's the error?!?[C++] |
|
|
I wrote this up in notepad quickly, there might be an error or two.
| Code: |
#include <iostream.h>
int main()
{
int choice; bool done = false;
do {
std::cout << "Insert a number";
std::cout << "from 1 to 5";
std::cout << ", 0 to quit";
std::cin >> choice;
switch (choice) {
case 1:
std::cout <<"Pfft, 1..." << endl; break;
case 2:
std::cout <<"OoOo, 1+1=2!" << endl; break;
case 3:
std::cout <<"O RLY? 3?!?" << endl; break;
case 4:
std::cout <<"Mamamia! itsa 4!" << endl; break;
case 5:
std::cout <<"Last owns all!" << endl; break;
case 0:
done = true; break;
default:
std::cin.sync();
std::cout << "Invalid input." >> endl;
break;
}
} while(!done);
std::cout <<"Ok, bye!" << endl;
std::cin.sync();
std::cin.get();
return 0;
}
|
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Dec 14, 2007 3:38 pm Post subject: Re: where's the error?!?[C++] |
|
|
| Flyte wrote: | | #include <iostream.h> |
| Code: | | #include <iostream> |
If there's only umm.. 6 different options, why to allocate sizeof(int) blocks memory?
| Flyte wrote: | | std::cin >> choice; | Check if it was done successfully.
| Flyte wrote: | | std::cout <<"Pfft, 1..." << endl; | std::cout, but endl? I'm not seeing any using;, but I'm seeing iostream.h.
| Flyte wrote: | | std::cout << "Invalid input." >> endl; | Rly?
| Flyte wrote: | | std::cin.get(); |
| Code: | std::cin.ignore();
std::cin.sync(); |
0 isn't always EXIT_SUCCESS.
| Flyte wrote: | | I wrote this up in notepad quickly, there might be an error or two. | I wrote this up in reply field quickly and drunk, there might be an error or two.
:P
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Dec 14, 2007 3:52 pm Post subject: Re: where's the error?!?[C++] |
|
|
Add this code to it
//something interactive...
//by teh 1338 nub zzoozz
#include <iostream.h>
using namespace std;
int main()
{
int choice;
...
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Dec 14, 2007 3:56 pm Post subject: Re: where's the error?!?[C++] |
|
|
| HornyAZNBoy wrote: | #include <iostream.h>
using namespace std; | Nonononononono, no!
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 14, 2007 4:17 pm Post subject: |
|
|
Heh, looking back on that I probably shouldn't have made it that early in the morning.
The computer I was on didn't have a compiler...
|
|
| Back to top |
|
 |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Sat Dec 15, 2007 4:26 am Post subject: |
|
|
dont complain about my code, im just learning c++ for like a week and 3 days...
thanks for fixing the code
EDIT:Error in compile, as i still didnt learnd that namespace new codes i cant find it
also its only 1 error
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Dec 15, 2007 11:26 am Post subject: |
|
|
| Make sure you fix all of the errors Jani found.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Dec 15, 2007 4:56 pm Post subject: |
|
|
| Flyte wrote: | | Make sure you fix all of the errors Jani found. | The errors are in your code, not his :P The only error I found in his code is this: | Jani wrote: | | Missing ; after return 0. You've to do a lot to improve your code. I have to say that your code is f'ugly. |
PS. Iono if he's concerning your version of the program as a "fixed" one. I'd say it's a rewritten one, not fixed.
|
|
| Back to top |
|
 |
|