Click here to Skip to main content
14,119,858 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i don't know what is the reason of of error.
i write it with c++ & i send what is it about.
it is the code:
<big>#include <iostream><br />#include <string><br />#include <cctype><br />using namespace std;<br />class cart{<br />public:<br />	cart(char a[2]="paq"){<br />		cout << a[0]<<a[1]<<a[2];};<br />	char left()<br />	{//int i;<br />		char a[2];<br />	swap(a[0],a[1]);<br />	//i++;<br />		for (int b=1;b>=2;b++)<br />			cout << a[b];<br />	return 'L';<br />	};<br /><br />    char right()<br />	{//int i;<br />		char  a[2];<br />	swap(a[2],a[1]);<br />	//i++;<br />		for (int b=1;b>=2;b++)<br />	cout << a[b];<br />	return 'R';<br />	};<br /><br />    char en()<br />	{//int i;<br />		char  a[2];<br />	swap (a[0],a[2]);<br />	//i++;<br />		for (int b=1;b>=2;b++)<br />	cout << a[b];<br />	return 'E';<br />	};<br />	char fo()<br />	{ //int i;<br />//	i++;<br />		char  a[2];<br />		for (int b=1;b>=2;b++)<br />	cout << a[b];<br />	return 'F';<br />	};<br />};<br /><br />int main ()<br />{cout << "swap the cart juker1,ace,juker2" <<endl;<br /><br />char b[50];char a[2];a[0]='p';a[1]='a';a[2]='q';<br />for (int i=1;i>=50;i++){<br />	cin >>b[i];<br />	if (b[i]='.') break;<br />};<br />	//cart y("p","a","q");<br />	cart x;<br />	for (int i=1;i>=50;i++){<br />	if ((b[i]='l')|(b[i]='L'))  x.left(); <br />	else if ((b[i]='r')|(b[i]='R')) x.right();<br />	else if ((b[i]='e')|(b[i]='E')) x.en();<br />	else if ((b[i]='f')|(b[i]='F')) x.fo();<br />	};}</big>

and it is what i want to do:
    
He has a table with three face-up cards in a row: two jokers and one ace, with the ace in the middle. After you make a small wager, he turns the cards face-down and begins to manipulate the cards, swapping cards two at a time. After he completes the swaps, you are then to guess which card is the ace.
The series of card swaps will be given to you in order as a String swaps, containing only the characters 'L', 'R', 'E', and 'F'. swaps[0] indicates the first swap. The 4 characters indicate the following moves:
L: swap the left and middle cards
R: swap the right and middle cards
E: swap the cards on the ends (the left and right cards)
F: fake swap (no cards actually change position)
Write a method that returns the final position of the ace, after all the swaps have been performed. Your method should return "L" if the left card is the ace, "R" if the right card is the ace, and "M" if the ace is in the middle.
thanks for attention
Posted

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

1) this sounds like homework - we dont do homework - at best we will give you hints, but if you're expecting us to jump in and solve all your issues, go to RentACoder or such

2) DONT GET IMPATIENT AND POST MORE THAN ONCE - most of us here have jobs we get paid to do, I doubt any of us get paid to help others on CP - except CP staff themselves, and most of them are involved with the actual running of the site, not answering questions

3) post in the correct forum - showing that you can do so indicates some level of intelligence - else, the responses you get will be rather 'trite' if not, brutal

Some suggestions :-

1) show what output you get - or where there's a compile error or such - I dont think you've actually stated what the problem/issue is

2) assuming your code compiles : learn how to use the debugger - use F10/F11 to single step through your program, inspect the contents of variables etc as you go - or at worst, print out their contents, then walk through what you're trying to do 'on paper' and see if that tells you whats going wrong.

3) comment your code - if you cant understand it, and cant tell us what each piece is doing, we wont spend much time on it either

4) looking at your code, I think you need to go back through your textbooks, a bit more .. for example char a[2]="paq" .. ok, so, if 'a' is a character array of size '2', how many characters are you trying to stuff in there - perhaps 3 ?? Im not sure what compiler you are using, but I can tell you in MSVC(6) you'll get "error C2117: 'paq' : array bounds overflow"

'g'
   
  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 27 Jan 2009
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100