Tuesday, July 14, 2009

Please help!!! C++ user defined funtions?

im trying to put some functions into my code. i want to create 2 functions in my switch statement one for case A and one for case B but im having trouble with my variables and the user input here is my code im open to any suggestions

#include %26lt;iostream%26gt;

using namespace std;

int main()


char choice; // variable for selection

int quantity; // variable for quantity of numbers

int num1; // variable for option A numbers

int num2; // variable for option B numbers

int largest; // variable for largest number

int smallest; // variable for smallest number


{ // beginning of do while loop

cout %26lt;%26lt; " Please choose one of the following options" %26lt;%26lt; endl; // instructions telling user what to enter

cout %26lt;%26lt; " A. - find the largest number with a known quantity of numbers" %26lt;%26lt; endl; //

cout %26lt;%26lt; " B. - Find the smallest number with an unknown quantity of numbers" %26lt;%26lt; endl; // display menu options to user

cout %26lt;%26lt; " C. - Quit" %26lt;%26lt; endl; //

cout %26lt;%26lt; " Please enter your choice: - "; //

cin %26gt;%26gt; choice; // ask user for input

cout %26lt;%26lt; endl; //

switch (choice)

{ // beginning of switch statement

case 'a': // case for when user selects option A

case 'A':

cout %26lt;%26lt; " A. - find the largest number with a known quantity of numbers" %26lt;%26lt; endl;

cout %26lt;%26lt; " Please enter the total quantity of numbers you would like to use: ";

cin %26gt;%26gt; quantity;

for (quantity;quantity %26gt; 0;quantity--)


cout %26lt;%26lt; " please enter a number - ";

cin %26gt;%26gt; largest;

cout %26lt;%26lt; endl;

for (quantity;quantity %26gt; 1;quantity--)


cout %26lt;%26lt; " please enter a number - ";

cin %26gt;%26gt; num1;

cout %26lt;%26lt; endl;

if (largest %26lt;= num1)

largest = num1;



cout %26lt;%26lt; " the largest number you entered is (" %26lt;%26lt; largest %26lt;%26lt; ")" %26lt;%26lt; endl;


case 'b': // case for when user selects option B

case 'B':

cout %26lt;%26lt; " B. - Find the smallest number with an unknown quantity of numbers" %26lt;%26lt; endl;

cout %26lt;%26lt; " enter your first number - ";

cin %26gt;%26gt; num2;

cout %26lt;%26lt; endl;

smallest = num2;

cout %26lt;%26lt; " to get result and return to main menu enter (-99) for your number" %26lt;%26lt; endl;

while (num2 != -99)


cout %26lt;%26lt; " please enter another number - ";

cin %26gt;%26gt; num2;

cout %26lt;%26lt; endl;

if (num2 != -99)

if (num2 %26lt; smallest)

smallest = num2;


cout %26lt;%26lt; " the smallest number you entered is (" %26lt;%26lt; smallest %26lt;%26lt; ")" %26lt;%26lt; endl;


case 'c': // case for when user selects to exit the program

case 'C':


default: // case for when user tries to select and option other than a, A, b, B, c, or C

cout %26lt;%26lt; " the letter you entered is not valid" %26lt;%26lt; endl;

} // end of switch statement

} while (choice != 'c'); // end of do while loop

return 0;


Please help!!! C++ user defined funtions?
create 2 functions called

void largest()


do all your things here;

returns nothing;


void smallest()


do all your things here;

returns nothing;

Reply:I see a problem with this section of code:

You are reading in a value for largest. That should only change when num1 is larger than largest's current value.

for (quantity;quantity %26gt; 0;quantity--)


cout %26lt;%26lt; " please enter a number - ";

cin %26gt;%26gt; largest;

cout %26lt;%26lt; endl;

for (quantity;quantity %26gt; 1;quantity--)


cout %26lt;%26lt; " please enter a number - ";

cin %26gt;%26gt; num1;

cout %26lt;%26lt; endl;

if (largest %26lt;= num1)

largest = num1;



C++, finding mode. It works - but is there an easier way?

void ord(double [], int);

int t, c = 0, count[50], p; double arr[50];

void main(){

cout %26lt;%26lt; "Postitive, 50 max, -1 to find mode)\n";

for (;;){

cout %26lt;%26lt; c + 1 %26lt;%26lt; ":%26gt;%26gt;";

cin %26gt;%26gt; t;

if (t == -1) break;

arr[c += 1] = t;}

ord(arr, c);

cout %26lt;%26lt; endl %26lt;%26lt; "Mode is: ";

int temp = count[1];

p = 1;

for (int i = 2; i %26lt;= c; i++){

if (count[i] %26gt; temp){

temp = count[i];

p = i;}}

cout %26lt;%26lt; arr[p] %26lt;%26lt; endl %26lt;%26lt; "Seen: " %26lt;%26lt; count[p] %26lt;%26lt; " times.\n";

system ("pause"); }

int f;

void ord(double arr[], int size){

for (int i = 1; i %26lt; size; i++){

for (int j = 1; j %26lt;= size; j++){

if ( arr[i] == arr[j] )


count[i] = f;

f = 0;}}

C++, finding mode. It works - but is there an easier way?
Your code is super sloppy.

Get the array populated then do this:

int size;

int array[50];

// assume size is the array length and array[size-1] is the last element.

for (int i = 0; i %26lt; size; i++)


int count = 0;

for (int j = 0; j %26lt; size; j++)




cout %26lt;%26lt; "Element: " %26lt;%26lt; array[i] %26lt;%26lt; " count: "%26lt;%26lt; count %26lt;%26lt; endl;

Reply:????????????????????????????? dorks Report It

Is a c cup bra big?

well,i'm thirteen years old in the eigth grade and i am a 32 c cup.my friend is 14 and a 36 c cup.and we were having a talk about whether a c cup is big,small,or in the middle.she said that a c cup is big and i said that it is right in the middle.i just recently became a c.cup. i was a 34 b and now a i'm a c.all my friends are making a big deal about my size.and i don't know why.my other friend is a 36 double d yeah i said it,and she says that a c cup is small.what do u think?

Is a c cup bra big?
haha well considering that im almost 18 and im a 34 A !!! haha yeah they are pretty big for your age. ( to me at least =p )

p.s. i am so jealous!!! =p =]
Reply:You are about average (:
Reply:A C cup is average. Yup.
Reply:i believe it depends on your weight, heath and state of mind, and generally C considered medium
Reply:It's a little above Average. B is average.

Your kickin some girls butts.


Reply:average but It depends on yuor body weight and height
Reply:its average
Reply:For me a C cup is big for a 13 year old...but thats because i'm a small B. It all depends on your figure.
Reply:I think C is average, there are big c's and smaller c's. A 36 c will look bigger than a 34c. Most girls also dont wear the correct size bra. You are very young, so I imagine they will still grow. So I hope you like em big
Reply:a c cup is medium to big. most 13 year olds are a b, but a 32c is not HUMONGOUS. but its not tiny either.
Reply:I think that for your age, you are a bigger average. I was very large at a 36 tripple D at your age. I now top out at 42 H. you are lucky to be the size you are.
Reply:i consider it big, not like ungodly huge, but very plump lol. considering i am a 34 A! and 16 yrs old!!! wooo and proud! hahah :)

Should I learn C before I learn C++?

I'm currently learning C++ as a hobby, but would love to find a programming job one day. I often see programming jobs that require you to have a background in C/C++.

Should I learn C before I learn C++? How difficult would it be to learn C later on after having programmed in C++ for a while?

Should I learn C before I learn C++?
Most programs like to teach C before C++. However, there is no reason why you shouldn't start with C++. One of the things people who start with C have a problem with is switching their thinking to an object oriented approach. I think if you start with C++ you can avoid this problem and I think going from C++ to C would actually be easier than going from C to C++.

If you go this route, make sure that whatever method you decide to use to learn, whether it be book or a course you enroll in or whatever, doesn't expect you to know C first. If they are teaching from an approach where they are building on C you may find yourself becoming frustrated.

Also I dissagree with Keena: I think it would be more like learning to ride a bike before learning to build it.
Reply:c lacks inheritance,polymorphism,classes, objects ,ect which is present in c++.........

ur idea would be like tryin to drive a bike b4 learning cycle.....lol......

u can , but am afraid it would be hard....
Reply:You should learn C++ first.

You will learn object oriented programming and you will have the opportunity to learn better practices, such as RAII. Also, the standard library in C++ does a lot more than the C standard library. You don't have to learn as much raw material before you can write a useful program. Most importantly, the C++ library does a lot of memory management for you (via container classes). Memory management is the most difficult part of C. Delaying that will get you up and running much faster.

In addition, raw C is not used much now, especially on desktop environments. It is used in specialized environments such as kernel drivers and embedded systems but stuff like that would be well in the future.

Once you know one language well, it is relatively easy to learn another. Going from C++ to C, you might miss the stuff you had, but it's not hard. You'll have to learn manual memory management, but it's not too bad once you have background.

Some of the best C++ learning books are:

C++ Primer 3rd ed, Stanley Lippman

The Complete C++ Training Course, Deitel %26amp; Deitel

You Can Do It- A beginner's introduction to Computer Programming!, Francis Glassborow
Reply:Just learn C++ because C is becoming more and more obsolete. C++ is one of the most prominently used languages out there and the language of choice in video games. C++ is a souped-up version of C, so learning C is pointless.
Reply:Yes it's always better to learn C first and I will explain why.

C is a very general purpose programming language. It is used to solve a wide range of programming problems. C++ takes it to another level by making object oriented programming a LOT easier while using the standard library provided by C. C does have advantages too such as a wide array of superior compilers to choose from.

You will not find C difficult after learning C++ because I learnt C++ 4 years before I even touched a C book. Personally, dealing with pointers in C was a pain in the neck whether you do it first or not you will have to do it at some point.

It's best to know both languages but just remember that 90%+ of all the programs out there can be written in either language.
Reply:C++ is EXTREMELY hard to learn. That is the reason why microsoft has invented C#. If you want to do something beneficial for your career learn C# instead. Ruby is also getting into demand %26amp; very user friendly. Forget C %26amp; C++ it is the PAST. Those 2 languages are use mostly in the research field but will dissapear.
Reply:I would lean towards C++. If you learn C++, then you are learning C with more features. C++ is just an extension of C, and you will probably find more job opportunities with C++.

Personally, I learned C first and C++ was extremely simple to learn afterwards. It would probably be the same if I knew C++ then tried to learn C.
Reply:I would suggest do your c++ first, because its a bit easier than C, when it comes to syntex of the commands that you need to write.

Once the logic of the code is clear to you.

You would find C quite easy to follow ...

The logic for both the land is the same but C is a bit more powerful as it gives you a bit more freedom with the assembly lang and hardware( but again slighly tougher than C++)...

my suggestion.. complete C++ and then C would be a cake walk for you.
Reply:in my opinion, you should learn C before C++

why? because it is easier and not that much "cryptic"

to understand than C++.. ^^

learn as much as you can in C, and when the time

that you're feeling that something (eg functionality, or

you cant code it easier) is missing while using C,

then its "time" for you to start to learn C++.. ^_^v

if you learn first C before C++, it is like

relearning C with some added functions

and another way to code a C program..

but the other way isn't.. if you first learnt C++ then C,

you may expect some functions to exists also

in C, which is often not.. why? because C is impossible

to be "backward" compatible with C++..

i hope you got my point.. peace out.. ^_^v
Reply:Ideally, you should learn C before C++ but you should be learning both at the same time.

Just to get a comparison between doing input/output statements and features in each language.

Or you can learn C then C++ then C# to see the differences in each language and the advantages of using each language.

It shouldn't be difficult to learn C after learning C++ but just having to remember that you cannot use 'class' in C and reference declarations.

In memory management, C uses malloc/free, C++ uses new/delete.

You don't need to cast a void* to pointer* where pointer is any type in C where as C++ requires you to do it.

C++ flags error where they are warnings in C.

easter cards

C programming book?

anyone pls tell me c programming book in tamil which is easy to understand?

who do not know in tamil , pls suggest c book in english?

also say for fresher interviews , what syllabus we hav to cover in c %26amp; c++?

how much time will take to complete c ?

thanks in advance!!!!

C programming book?
dude....try flazx.com
Reply:The first book i would suggest u is

"Progamming in c"-author-Balaguruswamy

following this book is easy

next very very very very interesting book is: "Let us C-author Yahwant kanikar"

While "programming in c by balaguruswamy" is easy to understand, Let us c book is also easy and very very very interesting with lots and lots lots of interesting examples... concepts of pointers,files etc are good in "let us c" book..

u can also refer schaum's programming in c

If u are fresher... And the time duration for fresher depends on their ability to understand concepts...

If u want to prepare urself for interview, and if u r non-computer student.... dont worry they wont ask u in deep about c... but u have to know what is what? its enough if u prepare a little on overall c. just learn what is what? like what diff between struct %26amp; union, what is a function,pointers,recursive function, file? what does a pointer,function,struct,union,files do?

what type of language is c? is it a structured or procedured language or such things....

Hope this helps a little!

All the very best!
Reply:I seriously doubt if any computer books come in languages other than English, especially the language books.

The only two books I have referred in my life are "Let us C" by Yashwant Kanitkar. This is the book, to start if you absolutely dont have any idea about what is C. The second book is Kernigham, ritchi. This is a must if you want to go deep and get all your fundaes clear. I will say before going to any C interview, have a look at this book.

Learning time depends on your grasping capability, and interest in subject, and also what you want to do. If you just want to write applications without knowing what happens inside compiler, learning the entire C language, will be matter of weeks. But if you want to get real champion, it can be matter of years. I am learning C from last 6 years.
Reply:how to c++ program for Deitel %26amp; Deitel
Reply:refer to Let us C -by yashwant kanitkar...

the time required to complete C depends on how deep u want to go in it n how much u r intrested in it.

for freshers interview prepare data structures becoz quests r mainly asked abt some DS algo..
Reply:for c language balagurusamy is good ,but for basic knowledge 'let us c'of yashvant kanitkar and 'c in depth' books are very good .

For good programming u have a good knowledge in pointer so give more concentrate in pointers.because in data structure programming

all prefer to use pointer for good programming .

For c++ I prefer mainly two books first ,'mastering c++' and 'reference to c++'.
Reply:Check out the book "OBJECT-ORIENTED PROGRAMMING WITH C++" by E. Balagurusamy --


To my knowledge the same author has written books on C as well.

If at all you are from Chennai, check out "Easwari Book house, T. Nagar", "Higginbothams, Mount road" or "Oddyssey in Adyar".


Reply:u can read

black book of c ,Mulish Copper C,Dummy C Programming
Reply:The best C programming book ever:

The C Programming Language (Second Edition) by Kernighan and Ritchie.

The authors created the language. The book is concise yet complete. You will find yourself going back to this book time and again, even after you have mastered the language.

3rd c-section, need advice?

I'm the mother of 2 boys and they were both c-sections the 1st time they induced my labor but my son was so big that he dropped fast and got stuck behind my cervix so they had to do an emergency c-section. (he was born 9 pounds 6.25 oz and was 22 1/2 inches long) The 2nd time despite the doctors efforts my 2nd son had refused to come out and they had no choice but to do a c-section. (he was 8 pounds 0 oz and was 21 1/2 inches long) the doctors are wanting to do a 3rd csection with this baby on 5/4/07 ( my 2nd born son's 2nd birthday)... I'm scared to have another c-section I remember all of the pain I went thru and the difficulty recovering. I want to have this baby natural but they claim it's too dangerous, has anyone else been thru this and had a normal vaginal delivery after multiple c-sections and what should I do about being scared of having another c-section. Should I try and talk my doctors into vaginally delievering anyway or waiting until its 2 late 4 them 2 do a section?

3rd c-section, need advice?
You can DEFINATELY have a VBAC. The least amount of medical intervention possible is always the best course of action. Learn all the risks of VBAC to see if it is right for you- it IS dangerous but SO IS normal labor.. SO IS a c-section.

You can tell your doctor you are going to try normal labor and see how it goes. If your doctor does not work on VBAC patients- find another.

C++ ,c++????

i've finished the tutorial for c++, the name of the tutorial is cpluscplus in .pdf format, then what?? and i cant see any thing that is relating windows applications and c++, like shutting down the pc with c++ code.. could u tell me how to improve my skill concerning windows with c++??,sorry if my question is rude, thnx for ur cooperation!!

C++ ,c++????
C++ is not a Windows PC language only. It is an utterly general language with compilers that target (almost) every (programmable) device and OS known to man. It is not surprising that a good, general introduction to C++ would not discuss or even mention Windows or PCs. C++ can be run on PCs, servers, mid-range, and mainframe boxes.

If your interest is Windows PC programming in C++, try:



You can get a bare-bones Visual C++ development tool from Microsoft at:

Reply:Check out these links:


www.cs.sjsu.edu/faculty/pearce/mfc/ (Microsoft Foundation Classes, an older technology use to interface the windows api from c++)

en.wikipedia.org/wiki/C++/CLI --a good starting point to learn about c++/cli, MS's new c++ flavor geared toward the .NET platform.

But if you really want to program windows, start looking into c#. It is based on c and c++. You will learn it in a flash. Then you can program windows through the .NET framework, where much of the windows API has been made easy to work with.
Reply:C++ is very powerful programming language . don't you know that they embed it on IC's .