Played half a game(well). Still gutted. (the Mrs aint)
easterbunny
commented:
well written and usefull +1
[URL="http://www.bbc.co.uk/news/uk-wales-south-east-wales-16929442"]Tread carefully![/URL] :)
In your program say i enter the number x=7
in your loop it goes
x(7)%i(2)!=0 so prime == 1
x(7)%i(3)!=0 so prime == 1
x(7)%i(4)!=0 so prime == 1 //needless since it cannot divide by 2
x(7)%i(5)!=0 so prime == 1
x(7)%i(6)!=0 so prime == 1 //same again
x(7)%i(7)==0 so prime == 0
If a number x, is not divisible by 2 then it can't be divisible by anything above x/2
If a number x, is not divisible by 2 or 3 then it can't be divisible by anything above x/3
etc...
Good kick under a [B]little[/B] bit of pressure, but a foul that makes the terrible sending off in the world cup look like a gentle hug.
The Mrs is happy so therfore i am happy.:)
The Super Bowl is an eighties soap (Dallas) but slightly faster and less interesting.
I have sent a memo to the PM asking for the Scottish team to be let loose in the wild then hunted by men on horses with a lot of dogs. He has yet to reply.:(
[QUOTE] the second term of the array and add it with the third term of this array[/QUOTE]
you are taking the third item twice i.e 3+3
[CODE]vector<vector> vec(a, vector(b));[/CODE]
Is this compilable? (i.e without the white space)
I think you want to look at [URL="http://www.daniweb.com/software-development/cpp/threads/395715"]this[/URL].
ok so number =3145
you need a nested loop so you can check pos1vpos2 pos1vpos3 pos1vpos4 pos2vpos3 etc...(or work back from pos4vpos3 doesn't matter)
(google bubble sort if you need to)
then you need to isolate the 2 numbers into variables, say a and b
i started my outer loop with i=length-1 and decremented i.
so a=num/pow(10.0,i)
a=(int)a%10
the 2 lines are because pow requires pow(double,int). got some compiler warnings with this.(I told you it was ugly)
inner loop starts at j=i-1
so b= same as above but with j not i.
now you have the 2 numbers to compare
if they need to be swapped then take them away from number ie number-=3000,number-=100 then add back in number+=1000, number+=300 (leave that code to you)
OK just done it i think.
Use a while loop for the length of the number.
Then sort the number checking each digit against the next (bubble sort) after separating them into 2 variables using / % and pow. If they need swapped remove the variables multiplied by the corresponding pow - then add by multiplying the variables by the correct pow and they should have swapped places. Using a nested loop to go right through the number.
Sorry i don't think i've explained it very well.
EDIT
Just ran it again and zeros are an issue. Doesn't work with them.
That can be fixed by checking the length at the end against the length at the start and outputting the appropriate number of zeros before the number.(UGLY i know)
Except leading zeros but who uses those.
What are 5 and 6 supposed to compute?
5) maybe %5
6) maybe /5
Break is used for stopping a loop. You are not using a loop.
Without the braces the loop only executes the one command after then exits after it has finished, then you output the final value of k.
[QUOTE]Frogboy,
You pretty much got what i needed bang on, But hahaa,
Dude you did all the work for me lol >"<[/QUOTE]
VERY little work involved.
I see no mention in the original post concerning arrays.
Again with no error checking.
Maybe i'm reading this all wrong but what's wrong with
[CODE]#include
using namespace std;
int main()
{
int quiznum;
double total=0,result,average;
cout<<"Enter amount of quizes: ";
cin>>quiznum;
for(int i=1;i<=quiznum;++i)
{
cout<<"Enter result: ";
cin>>result;
total+=result;
}
average=total/quiznum;
cout<<"\nThe average is "<<average<<"\n";
if(average>=75) cout<<"Pass\n";
else cout<<"Fail\n";
return 0;
}
[/CODE]
Why do you have 2 loops when you just add to sum after line 16.
This can be easily done without the need for arrays.
For b) what about
[CODE]((1 + (rand() % 5)) * 2)+1;[/CODE]
Sorry it was pretty late. The code was not intended to be handed in as is. The point i was trying to convey was that there seemed to be a lot of unnecessary work being done. Basically you only need to check the first character of the string against the last, then the second against the second last etc.. until you reach the middle.
[CODE]#include
using namespace std;
bool is_pal(string a)
{
int b=a.length();
for(int i=0;i<(b/2);++i)
if(a[i]!=a[b-i-1])return false;
return true;
}
int main()
{
string s;
cout<<"Please enter a string:\n";
cin>>s;
if(is_pal(s)) cout<<"This is a palindrome.\n";
else cout<<"This is not a palindrome.\n";
return 0;
}[/CODE]
Why the { on line 27?
What if n%10=1? i.e n=11 or 21?
EDIT
Beat me to that Nick:)
I have also been led to believe goto is BAD. A while or do while loop may be better.
It is repeating the loop. Try a couple of cout lines to find out where you're going wrong(ie right before line 21).