Fbody commented: Was this really necessary? -3
frogboy77 73 Posting Pro in Training
I gave you the answer dude.
What are 5 and 6 supposed to compute?
5) maybe %5
6) maybe /5
Point 2) from the OP is what i was looking for. (i.e the very detailed part)
Thread bump
Same question for windows
Break is used for stopping a loop. You are not using a loop.
if (ope == '+')
ope should be a char
What exactly is it that you are thankful for? (Genuine question)
so big me up
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.
1) Purchase a computer (guess this is covered)
2) Attain a compiler
3) Write the code
4) Compile and run
5) Job done
NO they are vegetables pretending to be fruit.
{} braces around your loop
Oh I thought you could enter like 5 integers at once almost like you can with characters into an array.
No if you want the individual digits in an array you will have to find a way to separate them. (there are a number of threads on this site with ideas about how to achieve this)
for the first question google SRAND
line 42 you create an array of ints then on line 45 you attempt to read a value to this array without specifying which location in the array you want to store it. I think you want to take in the digits of the guess into the array so you can check them one by one but this is not what you are doing.
Is there a reason you are not permitted to use strings and a simple loop?
Given the fact that of all the code posted on this thread (and there is more than enough) none of it is yours then an accusation of lack of effort i think is more than justified.
ask for input
store values
send information to average function
return average
print average
DONE
Frogboy,
You pretty much got what i needed bang on, But hahaa,
Dude you did all the work for me lol >"<
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
#include <iostream>
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;
}
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.
The only reason i have came across for a function with nothing sent to it and no return is output to the console.
Google cout.
You need to find out how to keep the console window open. see here to begin with
P.S you have no contingency for the numbers being the same.
For b) what about
((1 + (rand() % 5)) * 2)+1;
In what way?
What error are you getting?
it was a little too advanced for the class I'm in
I doubt it. I know nothing of classes or pointers so your code is beyond me.
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.
Of course they will probably work out a solution, but what will happen if the U.S. government shuts down?
Probably a lot of flag waving.:)
#include <iostream>
#include <string>
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;
}
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.
You failed yet?
And your question is?
@ mzimmers
nothing (but it's just a guess).
// system("pause"); - don't use this - not portable.
Is long long portable?
No, you are using double for a larger range of values. In this instance it is no more precise.
If you're like me and enjoy Steam's service (not having to mess with DVDs and CDs),
ok run your code and input 100.
Unless you are using vectors or strings to do this there has to be a defined limit.
c++ not python or ruby.
what about
#include <iostream>
using namespace std;
int fact(int a);
int main()
{
int num;
cout<<"Input number.\n";
cin>>num;
cout<<fact(num)<<endl;
return 0;
}
int fact(int a)
{
if(a==1)return 1;
else return a*fact(a-1);
}
why use double for a factorial problem?
And for the record i have taken Intro to CS, i understand most of the codding
I'm guessing this is Codding Studies. I am however curious if this is the successful harvesting of Pacific or Atlantic fish.;)
Does "friend" mean teacher?
You have far too much time on your hands.
Sometimes?