Monday, May 24, 2010

Ok last time im going to try this. Im coming up with a undeclared identifier error in main. this is c++?

/***************************************...


*


* Program name: Lab 10


* Author : Daniel J. Carr


* Date : December 10th, 2007


* Course/selection: CSC-110-003


* Program Description:


*


*


*


**************************************...


/************************** Compiler Directives **********************/


// libraries


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using namespace std;


/*********************** Global Data Declarations ********************/


/*************************** Function Prototype **********************/





void chop(float chipmunk,int%26amp; head,float%26amp; tail);





/*************************************...


*


* Function name: Main


* Author: Daniel J. Carr


* Date: December 10th, 2007


* Function Description:


*


* Pseudocode:


* Level 0


* -------


* Enter a float


* Chop it


* Output pieces


*


*


* Level 1


* -------


* Enter a float


* Display "Enter a floating point number----%26gt; "


* Input Chipmunk


* Chop it


* Call funtion chop to split chipmunk into head and tail


* Output Pieces


* Display "The whole number---%26gt; "%26amp; head %26amp; EOL


* Display "The Deciman number-%26gt; "%26amp; tail %26amp; EOL


*


**************************************...


int main()


{


//Varables


float chipmunk;


//arguements











cout %26lt;%26lt; "Enter a floating point number----%26gt; " %26lt;%26lt; endl;


cin %26gt;%26gt; chipmunk;





//Call function chop





cout %26lt;%26lt; "The whole number----%26gt; "%26lt;%26lt; head %26lt;%26lt; endl;


cout %26lt;%26lt; "The Decimal number--%26gt; "%26lt;%26lt; tail %26lt;%26lt; endl;








//Indicate successful termination of program





return 0;


}





//End main


/*************************************...


*


* Function name: Chop


* Author: Daniel J. Carr


* Date: December 4th


* Function Description:


*


* Pseudocode:


* Level 0


* -------


* Chop it


*


* Level 1


* -------


* Chop it


* whole = int(number)


* Decimal =|number-whole|


*


**************************************...





void chop(float chipmunk,int%26amp; head,float%26amp; tail)


{


// Variables





// Arguements


chipmunk = head;


tail = abs(chipmunk-head);








}

Ok last time im going to try this. Im coming up with a undeclared identifier error in main. this is c++?
//Call function chop





cout %26lt;%26lt; "The whole number----%26gt; "%26lt;%26lt; head %26lt;%26lt; endl;


cout %26lt;%26lt; "The Decimal number--%26gt; "%26lt;%26lt; tail %26lt;%26lt; endl;








Two problems


1) Main never calls the function chop (logic problem)


call chop(chipmunk,headmain,tailmain)


from the main program and declare variables headmain and tailmain in the main function. Also set headmain = 1 and tailmain = 1.f to avoid the variable is used without being set error.





2) In


cout %26lt;%26lt; "The whole number----%26gt; "%26lt;%26lt; head %26lt;%26lt; endl;


cout %26lt;%26lt; "The Decimal number--%26gt; "%26lt;%26lt; tail %26lt;%26lt; endl;


you try to use the variables declared ONLY inside the chop function in the main program (ONLY within the chop function can the head and tail variables be used)





Just move these statements inside the chop function (IE at the end of it) and they should work :-)
Reply:"head" and "tail" are never declared in main(). You attempt to set them, but they don't have a type associated with them or anything.





Also in chop() you are setting chipmunk, not head.
Reply:You are trying to reference 2 varibles that have not been declared.





Make it look like this...





//Varables


float chipmunk;


int head;


float tail;





Also, since 'abs' returns a double you should use the 'fabs' function instead.





2nd post:





Thats because you declared them, but not yet used them.


How do i keep the function getline for assigning to the next variable in C++?

when i run the program if u put a space in any of the strings it assigns the stuff after the space to the next string. how do i stop it so that the entire phrase is one and not two?





Code:


#include %26lt;iostream.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;string%26gt;


using namespace std;


string adja;


string namea;


string placea;


string adjb;


string thinga;


string nouna;





int main()


{


cout%26lt;%26lt;"Name a word that fits the description giving."%26lt;%26lt;endl;


cout%26lt;%26lt;"an adjetive"%26lt;%26lt;endl;


getline(cin,adja);


cout%26lt;%26lt;"a name"%26lt;%26lt;endl;


getline(cin,namea);


cout%26lt;%26lt;"a place"%26lt;%26lt;endl;


getline(cin,placea);


cout%26lt;%26lt;"a adjetive"%26lt;%26lt;endl;


getline(cin,adjb);


cout%26lt;%26lt;"a thing/noun"%26lt;%26lt;endl;


getline(cin,thinga);


cout%26lt;%26lt;"a thing/noun"%26lt;%26lt;endl;


getline(cin,nouna);


cout%26lt;%26lt;adja%26lt;%26lt;" "%26lt;%26lt;namea%26lt;%26lt;" was walking home from "%26lt;%26lt;placea%26lt;%26lt;" when a "%26lt;%26lt;adjb%26lt;%26lt;endl;


cout%26lt;%26lt;thinga%26lt;%26lt;" threw a "%26lt;%26lt;nouna%26lt;%26lt;" on top of "%26lt;%26lt;adja%26lt;%26lt;" "%26lt;%26lt;namea%26lt;%26lt;endl;


system("PAUSE");


return 0;


}

How do i keep the function getline for assigning to the next variable in C++?
It seems to work fine for me, and thats exactly what getline is for. What compiler are you using?
Reply:I hardly do anything in c++ anymore (C and C# mostly), but there are different ways to retrieve user input, some will split at the space, others will read until the end of the line. In C for example you have getc, read, etc.





I'd look at it from that angle.

flower garden

Complete the function .- Prints out the decimal digits of number in reverse order using c++?

#include %26lt;iostream%26gt;





using namespace std;





const int NUMBER_BASE = 10;





void reverseDigits(int number)


{





/* You are to write the code here to complete this function */





}





int main()


{


int n;


cout%26lt;%26lt;"Enter a 7 Digit number : ";


cin%26gt;%26gt;n;


reverseDigits(n);


return 0;


system("pause");


}

Complete the function .- Prints out the decimal digits of number in reverse order using c++?
use the shift operator %26gt;%26gt; for this.


there probably is a one line but this will also work a binary reverse. not exactly what you want ...





int x = 0;


for (int i = 0;i%26lt;32) { // 32 size of int


x = x%26lt;%26lt;1;


x = x + n%2;


n%26gt;%26gt;1;


}





//


int x = 0;


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


x = x + n%10;


n = n/10;


x *= 10;


}








and ? does it work already ?
Reply:It would be easier to store each digit in a different variable. Then use cout to print them in reverse order.





cout %26lt;%26lt; 7 %26lt;%26lt; 6 %26lt;%26lt; 5 %26lt;%26lt; 4 %26lt;%26lt; 3 %26lt;%26lt; 2 %26lt;%26lt; 1;


Please I want to connect two pointers and it is not working. i am programming in c++ with dev compiler.help me

/*i want to connect frisk pointer and blackee pointer please help me.thanks*/





#include %26lt;iostream%26gt;


using namespace std;


class Cat


{


public:


int GetAge();


void SetAge (int age);


void Meow();


Cat *blackee;


private:


int itsAge;


};


int Cat::GetAge()


{


return itsAge;


}


void Cat::SetAge(int age)


{


itsAge = age;


}


void Cat::Meow()


{


cout %26lt;%26lt; "Meow.\n";


}


int main()


{


Cat *Frisky;


Cat *blackee;


blackee-%26gt;SetAge(4);


Frisky-%26gt;blackee;





cout %26lt;%26lt; "Frisky is a cat who is " ;


cout %26lt;%26lt; Frisky/*.GetAge()*/ %26lt;%26lt; " years old.\n";


return 0;


}

Please I want to connect two pointers and it is not working. i am programming in c++ with dev compiler.help me
OK First of all you need to understand the difference between a pointer and an instance of a class.





Please read the references and they should explain to you why


blackee-%26gt;SetAge(4) is causing your program to crash and how to fix it.





Namely you need to create instances of Cat not just pointers to them. As for connecting them the pointers tutorial should help you out with that.
Reply:Its been a while since I have written in C, but I think there are 3 things I see:








(1) You need to allocate the memory for blackee based on your code here.





ie: Cat *blackee = new Cat();








(2) The second is on the assignment of Frisky to blackee, it should just be:





Friskey = blackee;








(3) Although it is commented out, you appear to be using the '.' operator for accessing the GetAge() method on Frisky. This should be the -%26gt; operator (because you are accessing the method on the pointer to the object). If you were accessing it on the object (ie: Cat Friskey;), then you could use the '.'.








In this instance, the code would have 2 pointers to the same Cat object. I am not sure if you need both objects (may if the assignment asks for it perhaps), but you could get away with the followibng code instead:





int main()


{


Cat *Friskey = new Cat();


Friskey -%26gt; SetAge(4);





cout %26lt;%26lt; "Friskey is " %26lt;%26lt; Friskey-%26gt;GetAge() %26lt;%26lt; " years old.\n";





return 0;


}








Although it might be interesting for you to do the following:





int main()


{


Cat *Friskey = new Cat();


Cat *blackee;





blackee = Friskey;





Friskey -%26gt; SetAge(4);





// both should be the same age.


cout %26lt;%26lt; "Friskey is " %26lt;%26lt; Friskey-%26gt;GetAge() %26lt;%26lt; " years old.\n";


cout %26lt;%26lt; "Friskey is " %26lt;%26lt; blackee-%26gt;GetAge() %26lt;%26lt; " years old (via blackee pointer).\n";





return 0;


}


How do you take the sin of a function in c++?

I am trying to perform sin(pi*0.5), but I cant get it to work. Here is my code:


#include%26lt;iostream%26gt;


#include%26lt;math.h%26gt;


using namespace std;


const double PI = 4.0*atan(1.0)


int main()


{


x = sin( pi*0.5 );


cout %26lt;%26lt; x;


}


It will not give the correct answer. Any help?

How do you take the sin of a function in c++?
error 1 -- x should be declared like





double x;





error 2 -- there is a ; at the end of const double ...





error 3 -- the const is PI all caps.





It works on my machine.


I would like to retrieve the output for exp(-1/2x) with a visual c++ compiler but all i get is 1. Please help.

#include%26lt;iostream%26gt;


#include%26lt;cmath%26gt;





int main()


{


using namespace std;


float y,x;





for(x=0;x%26lt;8;)


{


y = exp((-1/2)*x);


cout%26lt;%26lt;"y= "%26lt;%26lt;y%26lt;%26lt;"\n";


x = x + 0.1;


}





return 0;


}





Here's my attempt to code the function. What should I add?

I would like to retrieve the output for exp(-1/2x) with a visual c++ compiler but all i get is 1. Please help.
The problem lies in your "(-1/2)" portion of your code...change that to be "-0.5" ... that will solve your problem..





The reason why it didnt work is because in C/C++ when you have take 1/2 that says to the CPU to take two integers and the result is an integer and since 1/2 is 0.5 as a float BUT as an integer it is "0" so now your line will always try to do a exp(0) which means y will always equal to "1"....So either you change (-1/2) to be (-0.5) or you add a ".0" to the 1/2 ... such as "-1.0/2" or "-1/2.0" or "-1.0/2.0"...All those can fix your problem but the most elegant and fastest for the process would be to use "-0.5".

edible flowers

I can't get this program to work. What am i doing wrong .C++?

Write a funtion that uses a Rectange structure reference variable as its parameter and stores the user's input


in the structure's members.








#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;





struct Rectangle


{


int lenght;


int width;





};





void gettangle(Rectangle%26amp;);








int main()


{


Rectangle len;


gettangle (len);


return 0;


}





void gettangle(Rectangle %26amp;value)


{


cout %26lt;%26lt; "Enter Lenght:";


cin %26gt;%26gt; value.lenght;


cout %26lt;%26lt; "Enter Width:";


cin %26gt;%26gt; value.width;





}


void gettangle(Rectangle value)


{


cout %26lt;%26lt; value.lenght %26lt;%26lt; ":" %26lt;%26lt;value.width%26lt;%26lt; ":"%26lt;%26lt;endl;


}

I can't get this program to work. What am i doing wrong .C++?
Man, you're code is pretty hashed up. I don't know what you're trying to do in some of it.


First off, I see two Functions both with void type that operate on a given Rectangle's members (length, width). Both of which are named gettangle().


One of these functions takes the variable name, and the other takes the variable address. You only have one prototype above main. You have


void gettangle(Rectangle%26amp;);


you will also need one that takes a rectangle object (leave off the ampersand)


Second to that, your first function prototype is wrong and if you build your second prototype that you need the same way, it will be wrong too. You need to add in the variable name. You should have two prototypes and they will look like this.


void gettangle(Rectangle %26amp;value);


and


void gettangle(Rectangle value);


Now you're prototypes are right, let's move down to your functions. The first function you have is taking an address. Inside the function, to access the members of the rectangle object, you can't use the dot operator. Right now you're code looks like this "cin %26gt;%26gt; value.lenght;" It needs to look like this "cin %26gt;%26gt; value-%26gt;lenght;" Do you see the difference. You'll need a hyphen and the right arrow character to access the object members length and width.


That should do it for your functions.


Your main however is only going to run the program and it is going to run your second function running this code."{


cout %26lt;%26lt; value.lenght %26lt;%26lt; ":" %26lt;%26lt;value.width%26lt;%26lt; ":"%26lt;%26lt;endl;


}"


You're going to get output, but your rectangle variables haven't been set. You need to add the code "gettangle(%26amp;len);" in your main for it to ask you for the inputs before it outputs them. I think that's it. Make those changes and post if you're still not running.


BTW, the person above addressed that the compiler couldn't tell which function to use. That is correct, however if you have two prototypes up there, one that looks like this


gettangle(Rectangle%26amp; value);


(A note on the line of code above, I am not sitting at a compiler right now, so I can't check to see, but I'm not sure that that is where the ampersand goes to let the compiler know that it will be using an address. It may go just before the name like this %26amp;Rectangle, or it could go somewhere else. I just don't remember. So that may mess you up. Looking it up should be easy if you have a book or soemthign though.)


and another that looks like this


gettangle(Rectangle value);


it will be able to tell the difference just by whether you're passing in a object or an address. There isn't a need to rename the function however I would just because it's a good habit not to use the same function name for multiple operations, especially operations that have nothing to do with each other.
Reply:Generally if you provide the error message, it helps.





I think the problem here is that you have these two functions:





void gettangle(Rectangle %26amp;value);


void gettangle(Rectangle value);





Because both take a Rectangle, the C++ compiler can't tell which to use. You should rename the 2nd one to puttangle or similar (or change the function signature).
Reply:why r u having two gettangle function??


the program is already correct. if the problem is u not getting the output(cout%26lt;%26lt;value...)because u got 2 gettangle fuction.





ps:use system("pause"); in main fuction to see output :P


How do I make PI more accurate when inputting # of terms to calculate in C++?

It seems to be correct except that it outputs 4 as the answer everytime.





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include %26lt;string%26gt;


using namespace std;


double pi_one(int accuracy_func);


int accuracy=0;


long delta_input=0;


double show_pi=0;





int main( )


{


while(true){


cout %26lt;%26lt; "How accurate do you want me to calculate PI for you, i.e. # of terms:\n";





cin %26gt;%26gt; accuracy;


show_pi = pi_one(accuracy); //Invoke function #1





cout %26lt;%26lt; "Here you go. Have a nice day!\n" %26lt;%26lt; show_pi %26lt;%26lt; endl;








string ans = "x";


cout %26lt;%26lt; "Do you want to continue? (y/n)\n";


cin %26gt;%26gt; ans;





if(ans=="y"){


cout %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; "Let's do this again!\n" %26lt;%26lt; endl;


}





else if(ans=="n"){


cout %26lt;%26lt; "SEEEEEE you LATERRRR...\n";


return 0;





}





}


}





double pi_one(int accuracy_func)


{


double pi_total=0;





while(true){


for(double i=0; i%26lt;accuracy; i++){





pi_total += pow(-1.0,i)*(4/(2*i+1));





return (pi_total);


}





}


}

How do I make PI more accurate when inputting # of terms to calculate in C++?
Maybe I don't see it, but your while loop in main, when does it become False??? It calls the function but that also is while true.


Just do the for loop there.





I did the equation and it returns different answers. but the While Loops should not be like that.





While(ans=='y')


I am making a basic... win32 application using visual c++ 2008?

when i go to debug it though it gives me an error that says..





"1%26gt;.\Debug\ab.exe.intermediate.manifes... : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.


"





this is the code i have written....





#include %26lt;iostream%26gt;


using namespace std;





int main ()


{


cout %26lt;%26lt; "Nick's Gay!!!!" %26lt;%26lt; endl;


return 0;


}








what is the problem here???

I am making a basic... win32 application using visual c++ 2008?
Definitely sound like a problem with your solution/project file. Did you move or did anything to the project before running it?
Reply:Well, if you're getting an error regarding manifests, then you're making a .net console application. Remake the project and make sure that you select Win32 Console application, not a .NET application.





If that doesn't work. something might really be wrong
Reply:you sh oudl have written


int main


[[[[[


get off the computer and lets go to the mall


7383]


=]


;;;'


Why will this basic vector calculation not work in C++?

#include %26lt;iostream%26gt;


#include %26lt;math.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;iomanip%26gt;





using namespace std;





double x[50] = {0.0};


int j, M=5, N=1;


double P[350][350] = {0.0};





int main()


{


for (j = -M; j %26lt; M; j++)


P[N][j] = j+1;





for (j = -M+1; j %26lt; M; j++)


{


x[j] = (1*j)*P[N][j] + (j*(P[N][j+1] + P[N][j-1]));


cout %26lt;%26lt; endl %26lt;%26lt; " x= " %26lt;%26lt; x[j] %26lt;%26lt; endl;


}





getch();


return 0;


}

Why will this basic vector calculation not work in C++?
if M=5, the line for(j=-M;j%26lt;M;j++) will produce a value of -5 for j during the first time through your loop.





Since you use N and j as indicies into the P array, P[N][j] = P[1][-5] this is a problem: you have a negative index into your array.

covent garden

I need to create a diamond in C++?

It has to have asterisks in the shape of a diamond, and ask the user for the number of rows (between 1 and 19)


This is what i have already (its not much)





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using namespace std;





int main ()


{


int size;





cout %26lt;%26lt; "Enter a number of rows between 1 and 19" %26lt;%26lt; endl;


cin %26gt;%26gt; size;





if ( size %26lt; 1 || size %26gt; 19)


{


cout %26lt;%26lt; "you must enter a number between 1 and 19" %26lt;%26lt; endl;


return 0;

I need to create a diamond in C++?
Does not look easy, may be you can contact a C++ expert live at website like http://oktutorial.com/ .


If anyone has any experience with programming, specifically C++, can you help me with a simple script error?

Ok, so my calculator script works at first, when it asks for 1 number, then when it asks if I should add, subtract, etc, the second number is automatically set to a whack number. please help :D





My script (first part, i think the error is at the end, plus I just copy and pasted my script over for -, *, and /):


#include%26lt;iostream%26gt;


using namespace std;





int main(void)


{





system("TITLE My little Calcy, FO");


system("COLOR 2");


char cChar;


double dfirstnumber;


double dsecondnumber;


char cDoagain;





do


{





system("CLS");


cout %26lt;%26lt; "Insert the first number"


%26lt;%26lt; endl;


cin %26gt;%26gt; dfirstnumber;


cout %26lt;%26lt; "Enter the operation you would like to complete"


%26lt;%26lt; " (+,-,*, or /)" %26lt;%26lt; endl;


cin %26gt;%26gt; cChar;





cout %26lt;%26lt; "Enter 2nd number, hurry up also, I don't have all day"


%26lt;%26lt; endl;





switch (cChar)


{


case '+' :


cout %26lt;%26lt; "The answer is..." %26lt;%26lt; dfirstnumber %26lt;%26lt; " + " %26lt;%26lt; dsecondnumber %26lt;%26lt; " = " %26lt;%26lt; (dfirstnumber + dsecondnumber)


%26lt;%26lt; endl;


break;

If anyone has any experience with programming, specifically C++, can you help me with a simple script error?
When you asked for the second number, you forgot to read in their answer? cin %26gt;%26gt; dsecondnumber?

email cards

How do you fix this error in C++ or how would you rewrite this code?

this is the error i am getting: Error2 error C2181: illegal else without matching if





this is me code:





#include %26lt;iostream%26gt;


using namespace std;





using std::cout;


using std::cin;


using std::endl;


int main()





{


//declare variables


int people = 1;


int fee = 0;


int totalpeople = 0;


int totalfee = 0;





while(people %26gt; 0)


{


cout %26lt;%26lt; "Enter number of registrants for this company (Enter 0 to exit): " %26lt;%26lt; endl;


cin %26gt;%26gt; people;





if(people %26gt;= 1 %26amp;%26amp; people %26lt;= 3)


{


fee = 150;


}


else if(people %26gt;= 4 %26amp;%26amp; people %26lt;= 9);


{


fee = 100;


}


else


{


fee = 90;


}


totalpeople += people;


totalfee += (people * fee);


}





cout %26lt;%26lt; "Total people attending: " %26lt;%26lt; totalpeople %26lt;%26lt; endl;


cout %26lt;%26lt; "Total fee collected: " %26lt;%26lt; totalfee %26lt;%26lt; endl;


cout %26lt;%26lt; "Average fee per person: " %26lt;%26lt; totalfee / totalpeople %26lt;%26lt; endl;





return 0;


}

How do you fix this error in C++ or how would you rewrite this code?
Delete the semi-colon at the end of this line:


else if(people %26gt;= 4 %26amp;%26amp; people %26lt;= 9);


to take care of the compile error. Your logic is ok.





I doubt you need these lines:


using std::cout;


using std::cin;


using std::endl;





'using namespace std' should be all you need.


Error C4430: missing type specifier - int assumed. Note: C++ does not support default-int?

#include "stdafx.h"


#include %26lt;iostream%26gt;


using namespace std;





main()


{


int h;





cout %26lt;%26lt; "Enter an age and press ENTER: \n" %26lt;%26lt; h;


cin %26gt;%26gt; h;





if (h %26lt;= 0 %26amp;%26amp; h %26gt;= 12)


cout %26lt;%26lt; "The subject is a child.\n" %26lt;%26lt; h;





else if (h %26lt;= 13 %26amp;%26amp; h %26gt;= 19)


cout %26lt;%26lt; "The subject is a teenager.\n" %26lt;%26lt; h;





else if (h %26lt;= 20 %26amp;%26amp; h %26gt;= 60)


cout %26lt;%26lt; "The subject is an adult.\n" %26lt;%26lt; h;





else if (h %26lt;= 61 %26amp;%26amp; h %26gt;= 100)


cout %26lt;%26lt; "The subject is an adult.\n" %26lt;%26lt; h;





else


cout %26lt;%26lt; "The subject is dead.\n" %26lt;%26lt; h;





return 0;


}





can someone help me so the error goes away?

Error C4430: missing type specifier - int assumed. Note: C++ does not support default-int?
main()


...should be...


int main(void)





...aside from that, you should probably work on understanding how "else if" works.


Who can help me figure out?below is the question and my C++ code,but it cannot be compiled.
me figure out?

Implement the Stock Ticker structures:


* a gameState structure, that contains the number of times remaining to roll the dice, plus current values for all stocks;


* a Player structure, that records the player's stock holdings and the amount of cash that player has.


In your main program, create and initialize a gameState variable (5 dice to be rolled, all stocks at 1.00) and a 6-member array of Players (no stocks held, $5000 in cash for each player).





#include%26lt;iostream%26gt;


using namespace std;





int main()


{


struct GameState


{


int rollsRemainingInTurn;


float currentStockValues[6];


}


struct playerState


{


int stickHoldings[6];


float cash;


}


int i;


int j;


int k;


playerState player[6];


for(i=0;i%26lt;6;i++)


{


players[i].cash=5000.00;


}





for(j=0;j%26lt;6;j++)


{


players[i].stockHoldings[j]=0;


}


GameState game;


game.rollsRemainingInTurn=5;


for(k=0;k%26lt;6;k++)


{


game.currentStockValues[k]=1.00;


}

Who can help me figure out?below is the question and my C++ code,but it cannot be compiled.


me figure out?
Firstly, you shouldnt have your structures inside of your main() function. Pull them out so they are 'along side' it.





Next, I am pretty sure you're going to need semicolons ( ; ) after your structs ( }; )





Your loops for j is wrong. Your j loop needs to be inside of your i loop, just after you set the cash. That is, for each of your players you set its cash and you set each stock holding in each player.





Why do you have a ... after setting the currentStockValues ? That will not compile, you need a semicolon





You dont have an end brace } after your main function, nor do you have a return statement at the end.





It needs a lot of work!!!! :)





Do yourself a favor, dont try to put so much in the code at once. Start out with just getting an empty main() function to compile. Then put the standard "Hello World!" output in there.. Then add your structures, make sure they compile... add your initialization loops one-by-one. Keep testing your code as you go, it'll make things MUCH MUCH EASIER!





Edit- DarkTrooper's code below probably does compile now, but compiling and being correct are different things. :) His does not implement the loop correctly!
Reply:Hello,





Here's your code, now compilable with the appropriate fixes. I've commented those lines where you made errors.





int main()


{


struct GameState


{


int rollsRemainingInTurn;


float currentStockValues[6];


}; /* need semicolon here */





struct playerState


{


int stockHoldings[6]; /* renamed stickHoldings to stockHoldings */


float cash;


}; /* need semicolon here */





int i;


int j;


int k;


playerState players[6]; /* renamed variable player to players */





for(i=0;i%26lt;6;i++)


{


players[i].cash=5000.00;


}





for(j=0;j%26lt;6;j++)


{


players[i].stockHoldings[j]=0;


}


GameState game;


game.rollsRemainingInTurn=5;





for(k=0;k%26lt;6;k++)


{


game.currentStockValues[k]=1.00;


}





return 0; /* need to return an int value */


}


How do I do a for loop in C++ that will give me an output of 1-2-3-4-5-6-7-8-9-10. Mine is only giving me 10.?

#include %26lt;iostream%26gt;


using namespace std;





void main ()


{//begin main





//declare and initialize











int counter = 1;


int counter2 = 1;


int counter3 = 1;





//Process and Output








//For Loop: //test before


{





for(counter = 1; counter %26lt;= 10; counter++);


cout %26lt;%26lt; "Loop counter is at " %26lt;%26lt; counter %26lt;%26lt; endl;


counter = counter +1;





}





//While Do Loop: //test before








while (counter2 %26lt;= 10)


{





cout %26lt;%26lt; "Loop counter2 is at " %26lt;%26lt; counter2 %26lt;%26lt; endl;


counter2 = counter2 +1;


}





//Do While loop: //test after











do


{//begin loop





cout %26lt;%26lt; "Loop counter3 is at " %26lt;%26lt; counter3 %26lt;%26lt; endl;


counter3 = counter3 +1;





}//end loop


while (counter3 %26lt;= 10);





}

How do I do a for loop in C++ that will give me an output of 1-2-3-4-5-6-7-8-9-10. Mine is only giving me 10.?
In addition to the extra semi-colon (;), you are incrementing counter twice, so the output would be 1, 3, 5, 7, 9 for the for loop.





for(counter = 1; counter %26lt;= 10; counter++);


cout %26lt;%26lt; "Loop counter is at " %26lt;%26lt; counter %26lt;%26lt; endl;


counter = counter +1;





}





Should be


for(counter = 1; counter %26lt;= 10; counter++)


{


cout %26lt;%26lt; "Loop counter is at " %26lt;%26lt; counter %26lt;%26lt; endl;


}


Or


for(counter = 1; counter %26lt;= 10;)


{


cout %26lt;%26lt; "Loop counter is at " %26lt;%26lt; counter %26lt;%26lt; endl;


counter = counter +1;





}








Also, I would recommend getting in the habit of using counter++; instead of counter = counter + 1;


It looks better and is more efficient.
Reply:for(counter = 1; counter %26lt;= 10; counter++);





Is your culprit. By having the ; at the end. the loop does nothing. Remove the ; and the body of the loop will be run correctly.





Enjoy!


Can someone please help me with my c++ program?

program needs to ask the user to input the num of numbers they want to store in a vector, %26amp; print out the smallest num, the largest, %26amp; the average. this is my code but i get vector subscript out of range %26amp; i dont know wat to do


#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;


using namespace std;





int main ()


{


int numloop, value, small, large;


int sum=0;


double avg;


vector %26lt;int%26gt; vectorlist;





cout%26lt;%26lt;"Please enter the total number of numbers to be stored:"%26lt;%26lt;endl;


cin%26gt;%26gt;numloop;





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


{


cout%26lt;%26lt;"Please enter value to be stored:"%26lt;%26lt;endl;


cin%26gt;%26gt;value;


vectorlist.push_back(value);


}





small=vectorlist[0];


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


{


if(small%26gt;vectorlist[i])


small=vectorlist[i];


}





large=vectorlist[0];


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


{


if(large%26lt;vectorlist[i])


large=vectorlist[i];


}





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


{


sum+=vectorlist[i];


}


avg=sum/numloop;


cout%26lt;%26lt;"Smallest number:"%26lt;%26lt;small%26lt;%26lt;endl;


cout%26lt;%26lt;"Largest number:"%26lt;%26lt;large%26lt;%26lt;endl;


return 0;


}

Can someone please help me with my c++ program?
instead of writing all that. declare the vector AFTER you get input for how many numbers to use





ie





cout%26lt;%26lt;"Please enter the total number of numbers to be stored:"%26lt;%26lt;endl;


cin%26gt;%26gt;num;





edit: (been a while since C++)


vector %26lt;int%26gt;vectorlist(num); %26lt;- thats how it should look.





edit: also make sure you arent trying to acces part of a vector thats out of its bound. i had that mistake once where i had a loop start at 1 and not 0 but it ended 1 after the last spot in teh vector.





also you didnt declare i.








okokok i got it:


#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;


using namespace std;





int main ()


{


int num, value, small, large, i;


int sum=0;


double avg;








cout%26lt;%26lt;"Please enter the total number of numbers to be stored:"%26lt;%26lt;endl;


cin%26gt;%26gt;num;





vector %26lt;int%26gt;vectorlist(num);





for (i = 0; i %26lt; num; i++)


{


cout %26lt;%26lt; "enter number" %26lt;%26lt; endl;


cin %26gt;%26gt; value;


vectorlist[i] = value;


}





small=vectorlist[0];


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


{


if(small%26gt;vectorlist[i])


small=vectorlist[i];


}





large=vectorlist[0];


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


{


if(large%26lt;vectorlist[i])


large=vectorlist[i];


}





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


{


sum+=vectorlist[i];


}


avg=sum/num;


cout%26lt;%26lt;"Smallest number:"%26lt;%26lt;small%26lt;%26lt;endl;


cout%26lt;%26lt;"Largest number:"%26lt;%26lt;large%26lt;%26lt;endl;





system("PAUSE");


return 0;


}

baseball cards

Converting a string, to a vector of ints, to binary, to hexadecimal. (C++)?

I need to create a program that will accept a string inserted by the user, which represents an unsigned int. I need to convert this string to a vector of ints, and then convert the number to binary and hexadecimal. This is what I have so far:





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;


#include %26lt;string%26gt;


#include %26lt;cstdlib%26gt;





using namespace std;


int main(void)


{


cout%26lt;%26lt;"Input a decimal:"%26lt;%26lt;endl;


string s;


cin%26gt;%26gt;s;





vector%26lt;int%26gt;n(s.length());





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


{


n[i] = s[i] - 48;


}





return 0;


}

Converting a string, to a vector of ints, to binary, to hexadecimal. (C++)?
Your code assumes that the string entered only contains ASCII digits. You should explicitly check for this:





if ( isdigit( s[i] ) ) {





Next, you can also use a standard function to convert a string to an integer for you:





n[i] = atoi( s[i] );





(if you ever want to convert the entire string to a single integer, you could use strtol() ).





Give these a whirl and see where you end up. Go to the URL below and type "atoi" in the search field.


How to format output with setw() in C++?

In my code i need the output to be seperated by 5 spaces (wich i have alread done as you can see) but now i need it only to print 10 words/numbers per line insted of stretching the whole window long. How would I do this using %26lt;%26lt;endl? if so how becasue i have entered it but can get it right. Thanks





heres the code





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


bool bip(int num)


{


if (num % 3 == 0)


return true;


else


return false;


}


bool bop(int num)


{


if (num % 7 == 0)


return bop;


else


return false;


}


int main()


{


int num;


for(num= 1; num %26lt; 101; num++)


{


if(bop(num) == true)


cout %26lt;%26lt;setw(5) %26lt;%26lt;"bop";


else if(bip(num) == true)


cout %26lt;%26lt;setw(5) %26lt;%26lt;"bip";


else


cout %26lt;%26lt;setw(5) %26lt;%26lt;num; }


}

How to format output with setw() in C++?
Inside your for-loop put this check first.





if ((num % 10) == 0)


{


cout %26lt;%26lt; endl;


}





Also, it may be a typo but in bop() you are trying to return bop rather than true.


Need a programmers help with my C++ Program?

Read the additional info for what I need thank you!





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int temp;








int main()


{


int numbers[5];


int counter;


string str;











cout %26lt;%26lt;" Welcome!";


cout %26lt;%26lt;"Please enter 5 numbers with spaces in between: ";





for (counter = 0; counter %26lt; 5; counter++)


{


cin %26gt;%26gt; numbers[counter];


}





cout %26lt;%26lt; endl;








cout %26lt;%26lt;" The numbers in reverse order are: ";





for (counter = 4; counter %26gt;=0; counter--)





cout %26lt;%26lt; numbers[counter] %26lt;%26lt; " ";


cout %26lt;%26lt; endl;








cout %26lt;%26lt;"\nEnter 5 words: "%26lt;%26lt;endl;


while (counter %26lt; 4)


{





cout %26lt;%26lt; "Enter word "%26lt;%26lt;counter + 2%26lt;%26lt;" :";


cin %26gt;%26gt;str;


cout%26lt;%26lt;"First Letter of Your Word is: "%26lt;%26lt;str[0]%26lt;%26lt;" and the third letter is: "%26lt;%26lt;str[2]%26lt;%26lt;endl;


counter++;








}

















return 0;


}

Need a programmers help with my C++ Program?
to read to and from a file, you need


#include%26lt;fstream%26gt;





then define the file you want to read to as an "ofstream" type:


ofstream output_example("output_file.txt");





so instead of





cout%26lt;%26lt;.....


now you want to write





output_example%26lt;%26lt;.......%26lt;%26lt;endl;





and so on- this will write your numbers to a file named output_file.txt


Passing an Array to a Function C++?

what am I doing wrong? Im trying to simply pass the array testvals to calcaverage. I just want the program to calculate the average and then pass the average calculated back to main.





I get an error of "variable-sized object `testvals' may not be initialized "








#include %26lt;iostream%26gt;


using namespace std;





int calcaverage(int);





int main()


{


int NUMEL, average;


int testvals[NUMEL] = {89,95,72,83,99,54,86,75,92,73,79,75,82,...





cout %26lt;%26lt; "WELCOME! ";





average = calcaverage(testvals[NUMEL]);


cout %26lt;%26lt; "the average of these numbers is: " %26lt;%26lt; average;











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


system("PAUSE");


return 0;





}





int calcaverage(int testvals)


{





int i, average=0, total=0, NUMELS=14;





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





total += testvals;


average = total/14;





return average;


}

Passing an Array to a Function C++?
You never initialize NUMEL to a value, so what size is testvals[] suppose to be?





Pass the array AND the size of the array to calcaverage(). The function prototype can then be calcaverage(int a[], int size). It currently is just taking a single int.





In calcaverage(), there is no need to define variable i twice - or NUMELS at all. Now that you are passing a valid array to the function you have to address it with a subscript.





Below are the corrections.





#include %26lt;iostream%26gt;


using namespace std;





int calcaverage(int testvals[], int size);





int main()


{


const int NUMEL = 14;


int average;


int testvals[NUMEL] = {89,95,72,83,99,54,86,75,92,73,79,75,82, 88};





cout %26lt;%26lt; "WELCOME! ";





average = calcaverage(testvals, NUMEL);


cout %26lt;%26lt; "the average of these numbers is: " %26lt;%26lt; average;





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


system("PAUSE");


return 0;


}





int calcaverage(int testvals[], int size)


{





int average=0, total=0;





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


{


total += testvals[i];


}





average = total / size;





return average;


}
Reply:DO NOT use C-style arrays in C++. That is just plain bad style. Try using std::vector%26lt;int%26gt; instead. See http://www.cplusplus.com/reference/stl/v...





But if you insists using the C style arrays:








The function prototype for calcaverage should be:





int calcaverage(int testvals[NUMEL] )





OR





int calcaverage(int * testvals , int numtestVals)





Which I prefer more.





Then call





calcaverage(testvals)





OR





calcaverage(%26amp;testvals[0], NUMELS)
Reply:I don't think thats the correct way of passing array to the function:


the signature of the function should be like this:


int calcaverage(int testvals[]);





to call this function you simply have to do this:


average = calcaverage(testvals);





and also the NUMEL should be some initialized constant.


const int NUMEL = 5;

artificial flowers

Having a problem with if, else if, and else statements in C++...?

I'm having a problem making a program that calculates angle measures. Whenever a user types an input for the variable "input", it doesn't recognize it even if it is typed in correctly, and goes directly to do else statement, "Invalid command." What's wrong, how do I fix this? Thanks.





#include %26lt;iostream%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;string%26gt;


using namespace std;


int main(int argc, char *argv[])


{


cout %26lt;%26lt; "Please enter in Sum Of Angles or Angle Measure" %26lt;%26lt; endl;


string input;


cin %26gt;%26gt; input;


if (input == "Sum Of Angles")


{


cout %26lt;%26lt; "Please enter number of sides of your regular polygon" %26lt;%26lt; endl;


int a;


cin %26gt;%26gt; a;


cout %26lt;%26lt; "Your answer is " %26lt;%26lt; (a - 2) * 180 %26lt;%26lt; endl;


}


else if (input == "Angle Measure")


{


cout %26lt;%26lt; "Please enter number of sides of your regular polygon" %26lt;%26lt; endl;


int b;


cin %26gt;%26gt; b;


cout %26lt;%26lt; "Your answer is " %26lt;%26lt; (b - 2) * 180 / b %26lt;%26lt; endl;


}


else {


cout %26lt;%26lt; "Invalid Command" %26lt;%26lt; endl;


}


system("PAUSE");


return 0;


}

Having a problem with if, else if, and else statements in C++...?
Replace the line (near the top):





cin %26gt;%26gt; input;





with:





getline(cin, input);





And that should do it. When using cin to read a string, it only reads up until the first whitespace character that's typed (space, tab, or newline). getline, here, reads from cin into input up until the newline character you type when you press [ENTER].





So, as it was originally, when you type "Sum Of Angles" it would read the word "Sum" into the input variable, and then hold onto the "Of Angles" for future calls to cin.





So, if I did this:


string a, b ,c;


cin %26gt;%26gt; a;


cin %26gt;%26gt; b;


cin %26gt;%26gt; c;


and typed "Sum Of Angles" all at once and pressed [ENTER], "Sum" would end up in a, and it wouldn't have bothered to wait for me to type anything and press [ENTER] again for b or c. I had typed three things separated by spaces all at once, so it would immediately place "Of" in b and "Angles" in c.





The Psyco's answer is correct if we were talking about c strings here, but you're using a c++ string. C strings are pointers to arrays of characters ( char* ) and c++ strings are objects of a class called string, which you use here.





if ( !strcmp( input , "Sum of Angles" ) )


would only work if input was as c string. So doing that won't even compile. However, you could have done:





if ( !strcmp( input.c_str() , "Sum of Angles" ) )





c_str() is a function of the string class that returns a c++ string object as a c string. The reason if(input=="Sum Of Angles") works is because of "operator overloading". I mean, the "==" operator is redefined for use with c++ strings, so it actually compares the contents of the two strings.
Reply:You can't use ... if ( input == "Sum of angles" )





What that test does is you are comparing the memory address of the variable input to the memory address of "Sum of Angles", which will never be equal.





If you are comparing strings, you need to use STRCMP.





say...





if ( !strcmp( input , "Sum of Angles" ) )


{


...


}





See the command here..





http://www.cplusplus.com/reference/clibr...
Reply:Looks like it is your homework assignment. Consider contacting a freelancer at websites like http://getafreelnacer.com/


I need a program in c++ that read an archive?

The archive is like this: avemaria { anormal } . Ok I need that the program separate the word "anormal" and put it in a queue.


This is what I got:


#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include%26lt;cassert%26gt;


#include%26lt;string%26gt;


using namespace std;





int main()


{


ifstream archivo;


string reading,


palabras;





getline(cin, palabras);


archivo.open(palabras.data());


assert( archivo.is_open() );





for (;;)


{


archivo %26gt;%26gt; reading;





if ( archivo.eof() ) break;


if ( reading == "{")


cout%26lt;%26lt;reading;


cout%26lt;%26lt;" ";


}





system("pause");


}





Please, help me.


Thanks

I need a program in c++ that read an archive?
Read the string. When you get to the "{", read the following characters into the queue until you get to the "}". (It's called a state machine, and this one is trivially simple.)


I have this program in c# for constructors.it gives the output as 12 &13.can any1 tell me how its possible?

using System;


namespace CalculateNumber


{


class Calculate


{


static int number1;





public void Display(int number)


{


Console.WriteLine(number);


}


Calculate()


{


number1++;


Display(number1);


}


static Calculate()


{


number1 = 10;


number1++;


}





static void Main()


{


Calculate cal1 = new Calculate();


Calculate cal2 = new Calculate();


Console.ReadLine();


}


}


}

I have this program in c# for constructors.it gives the output as 12 %26amp;13.can any1 tell me how its possible?
static Calculate()


{


number1 = 10;


number1++;


}


here you have initialize the number1=10


then "number1++" will make it 11,





Calculate()


{


number1++;


Display(number1);


}


here you made it to number1++ so it will become 11+1=12;


and called Display Method,So it will display 12


Again you are calling the same function by instantiating it (cal2) so it will became12+1=13 and Display.....





Ans.Static Constructors will be executed only once as opposed to other constructors which are executed whenever an object of the class is created......


I hope i have clear your doubt............ss.pandey@tcs.com


How would i do this c++ program without using boolean?

# include %26lt;iostream.h%26gt;


# include %26lt;iomanip.h%26gt;


#include %26lt;ctype.h%26gt; // needed for toupper


#include %26lt;stdlib.h%26gt;// needed for rand


#include %26lt;fstream.h%26gt;





using namespace std;





int main ( )


{





int num[20]={0};





const int numLength = 20;





for(int count = 0;count %26lt; 20;count++)


{


cout%26lt;%26lt;"enter 20 numbers with


repeating numbers"%26lt;%26lt;endl;


do{


cout%26lt;%26lt;"enter number "


%26lt;%26lt;(count+1)%26lt;%26lt;": "%26lt;%26lt;endl;


cin %26gt;%26gt; num[count];


}


while (num[count]%26lt;10


|| num[count] %26gt; 100);





}


cout %26lt;%26lt; "The original set of numbers were: ";





for(int countfun = 0;countfun


%26lt; 20;countfun++)


{


cout %26lt;%26lt; num[countfun]


%26lt;%26lt; setw(3);





}





cout %26lt;%26lt;"\nThe different numbers


from the set of integers are: ";





return 0;


}





I'm supposed to have 20 random numbers with repeating variables.





Example: My numbers 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2





Original set of numbers: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2


New set of numbers: 1 2





I can't use boolean to remove the duplicates. How would I do this? Thanks.

How would i do this c++ program without using boolean?
After you assign a number into the array, test whether that number is equal to any other array member. If it is a match, then do not increment to the next array member, because you want to assign the next number into that same array member. If it is not a match then you assign the next number to the same array member.





For example, the value of num[0] is 1 and you assign 1 into another array member, here's the test:


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


if (num[i] == num[0]) count--;





Now you might have another problem, because each time you decrement "count", your other loop "for(int count = 0;count %26lt; 20;count++)" will run an extra iteration. That problem can be solved by using a variable such as "max" instead of the literal number "20", and decrementing "max" when you decrement "count". So now the test will look like this:


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


if (num[i] == num[0])


{


count--;


max--:


}
Reply:This sounds like a class project, so I'm not going to give you any code so that you won't be accused of cheating. That being said, here are a couple of solutions.





Get the instructor to define "can't use boolean." Are you not allowed a boolean variable? What about a method that returns a boolean?





If you can use a method, that is how I would do it:


bool duplicateFound(int* original_set, int num_to_check)





if that is not allowed, remember that in C++, boolean is really an integer. False is 0, anything else is true. But this is really cheating.





How about a recursive method that returns the duplicate?





int recursiveCheck(int* num_to_check, num)


{


//check the first number and you are not at the end of the array


// if check fails, increment the pointer and call this function


}

800flowers.com

I am working on an C++ encryption program and I can use some help?

Develop a program that performs simple cryptography. The program will allow


the user to enter a string and a cryptographic key, and the program will then encrypt the string using the key and send the output of the encryption to a f\ile.


This is what I have so far


#include %26lt;iostream%26gt;


#include%26lt;string%26gt;


using namespace std;


class Message


{


private:


string content;


int location;


public:


Message() : content(""), location(0) {};


Message(string s) : content(s), location(0) {};


string print() const;


void addToContent(string s);


};


string Message::print() const


{


return(content);


}


void Message::addToContent(string s)


{


content.append(s);


}


int main ()


{


string input;





cout %26lt;%26lt; "enter some text: ";


getline(cin, input);





Message rect(input);





cout %26lt;%26lt; "\nText was: " %26lt;%26lt; rect.print() %26lt;%26lt; endl;





return 0;


}

I am working on an C++ encryption program and I can use some help?
So what, exactly, is your question?

wildflower

Cant figure out whats wrong C++?

//Class declaration for the rectangle class





class house


{


public:


//default constructor


house():





house(double l, double w, double h, double R_wall, double R_ceiling, double in_temp, double out_temp);





//accesor funtions


double get_length() const;


double get_width() const;


double get_height() const;


double get_R_walls() const;


double get_R_ceilings() const;


double get_in_temp() const;


double get_out_temp() const;





//function for input and output.





double input(istream%26amp; in);


double output(ostream%26amp; out) const;





//additional member function prototypes.


void set_value(double l, double w, double h, double R_wall, double R_ceiling, double in_temp, double out_temp);


double area() const;





private:


//declaration of data members;


double length, width, height, R_walls, R_ceilings, in_temp, out_temp;


};


#endif


























#include %26lt;iostream%26gt;


using namespace std;


using :: istream;


using :: ostream;





house:house(double l, double w, double h, double R_wall, double R_ceiling, double in_temp, double out_temp);


length(l), width(w), height(h), R_walls(R_wall), R_ceilings(R_ceiling), in_temp(in_temp), out_temp(out_temp);


{


}





void house::set_value(double l, double w, double h, double R_wall, double R_ceiling, double in_temp, double out_temp)


{


//set the value of the calling object.


length = l;


width = w;


height = h;


R_walls = R_wall ;


R_ceilings = R_ceiling;


in_temp = in_temp;


out_temp = out_temp;


return;


}

Cant figure out whats wrong C++?
1.)


When you declare house::house(), you should write "house();" not "house:". Using a colon instead of a semicolon makes the compiler expect to see an initialization list.





2.)


When you define house::house(), you should write "house::house", not "house:house", because "house::house" is the fully-qualified name of the function, whereas "house:house" is simply an illegal construct.





3.)


When you give an initialization list for house::house, you should not terminate the initialization list in a semicolon. The initialization list is terminated by the open brace.





4.)


You appear to be missing the definitions of a number of other functions.





5.)


You should define a copy constructor "house::house(const house%26amp;)", and then you can simply use the default assignment operator instead of set_value.


What is wrong with my C++ code?

#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


int main ()





{


int i,k,n=1,m;


cout%26lt;%26lt;"Enter height"%26lt;%26lt;setw(11)%26lt;%26lt;":";


cin%26gt;%26gt;n;


for(m=0; m%26lt;2; m++)


{


for(i=1; i%26lt;=n; i++)


{


if(m==0)


{


for(k=1; k%26lt;=n-1; k++)


{


cout%26lt;%26lt;"";


}


for(k=1; k%26lt;=2*i; k++)


{


cout%26lt;%26lt;"^";


}





}


if(m==1)


{


for(k=1; k%26lt;=i; k++)


{


cout%26lt;%26lt;"";


}


for(k=1; k%26lt;(n-i)*2; k++)


{


cout%26lt;%26lt;"^";


}


}


cout%26lt;%26lt;endl;


}


}


return 0;


}





My errors,





pyr2.obj : error LNK2005: _main already defined in pyramid.obj


Debug/pyramid.exe : fatal error LNK1169: one or more multiply defined symbols found


Error executing link.exe.





pyramid.exe - 2 error(s), 0 warning(s)

What is wrong with my C++ code?
It looks like you have a pyr2.cpp and pyramid.cpp file that both define the function main. If you are linking these two files together only one of them can define the function main.
Reply:What's probably the problem is that main is defined as








int main( int argc, char *argv[])





by having main(), it thinks you're trying to redefine it.
Reply:May be you can post your requirements at http://expert.ccietutorial.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.
Reply:You are linking more than one file with a main function in it.


I need help with functions!!! c++ please!?

#include %26lt;iostream%26gt;





using namespace std;


int stores(int);





int main()


{


stores(int);





system("pause");


return 0;


}





void stores(int)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;

















}








it doesnt work for some reason plz help

I need help with functions!!! c++ please!?
Your "stores" function is prototyped to return "int", but it is defined to return "void". You should fix that; I think the second one is wrong. If you do that, then you need to add a return statement to your "stores" function.





Also, when you call "stores" in the main program, you are passing the value "int". That is not correct either. It should be an integer constant or the name of an integer variable or some other expression that yields an int. The word "int" is not what you want.





In fact, I can't see what you need that int for anyway. Apparently neither do you since you did not give your int parameter a name when you defined the function.





I suggest that you change the prototype to something like this:


-------------------


int stores(void);


-------------------





Change the actual call in the main program to something like this:


-------------------


cout %26lt;%26lt; "You picked " %26lt;%26lt; stores() %26lt;%26lt; endl;


-------------------





And change the actual function definition to something like this:


-------------------


int stores(void)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;


return store_choice;


}


-------------------





I think you will be much happier with the result.
Reply:#include %26lt;iostream%26gt;





using namespace std;


int stores(int);





int main(int) %26lt;------Heres what i added different


{


stores(int);





system("pause");


return 0;


}





void stores(int)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;

















}
Reply:I'm weak in functions so this will help but not all the way.





Shouldn't this be at the bottom?





System pause is so the screen won't close on you but there should be a return 0 at the very bottom. Is there a return 0 necessary within the function too?





system("pause");


return 0;


I need help with functions!!! c++ please!?

#include %26lt;iostream%26gt;





using namespace std;


int stores(int);





int main()


{


stores(int);





system("pause");


return 0;


}





void stores(int)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;

















}








it doesnt work for some reason plz help

I need help with functions!!! c++ please!?
Your "stores" function is prototyped to return "int", but it is defined to return "void". You should fix that; I think the second one is wrong. If you do that, then you need to add a return statement to your "stores" function.





Also, when you call "stores" in the main program, you are passing the value "int". That is not correct either. It should be an integer constant or the name of an integer variable or some other expression that yields an int. The word "int" is not what you want.





In fact, I can't see what you need that int for anyway. Apparently neither do you since you did not give your int parameter a name when you defined the function.





I suggest that you change the prototype to something like this:


-------------------


int stores(void);


-------------------





Change the actual call in the main program to something like this:


-------------------


cout %26lt;%26lt; "You picked " %26lt;%26lt; stores() %26lt;%26lt; endl;


-------------------





And change the actual function definition to something like this:


-------------------


int stores(void)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;


return store_choice;


}


-------------------





I think you will be much happier with the result.
Reply:#include %26lt;iostream%26gt;





using namespace std;


int stores(int);





int main(int) %26lt;------Heres what i added different


{


stores(int);





system("pause");


return 0;


}





void stores(int)


{


int store_choice;


cout %26lt;%26lt; "Welcom to my shop! What would you like to buy?" %26lt;%26lt; endl;


cout %26lt;%26lt; "1. weapons... 2. shields... 3. guns... 4. boats..." %26lt;%26lt; endl;


cin %26gt;%26gt; store_choice;

















}
Reply:I'm weak in functions so this will help but not all the way.





Shouldn't this be at the bottom?





System pause is so the screen won't close on you but there should be a return 0 at the very bottom. Is there a return 0 necessary within the function too?





system("pause");


return 0;

tarot cards

What's wrong with my C++ code on classes?

This is my Class code, copied straight from my professor's notes. It's not working. I've got a final tomorrow on this stuff and need to know what's going wrong. The error that it keeps catching on is "new types may not be defined in the return type" under Stack::Stack().





#include %26lt;cstdlib%26gt;


using namespace std;





class Stack {


private:


int top;


int contents[100];


public:


Stack();


void stackPush(const int item);


void Pop();


int stackTop() const;


}





Stack::Stack()


{


top=-1;


}





void Stack::stackPush(const int item)


{


contents[++top]=item;


}





void Stack::Pop()


{


top--;


}





int Stack::stackTop() const


{


return contents[top];


}

What's wrong with my C++ code on classes?
You need a semicolon after the end of your class definition.


Pass by reference functions in C++?

write a pass by reference functions for 3 courses u take


the course name (without spaces)


number of creds


grade value (decimal number)





so far i got the value ret function right but im stuck my code so far is





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;


//fn prototype for passing num of students in class


void DisplayStudent(double num, double answer);


void DisplayName(coursename%26amp;);














int main ()


{


double num,answer;


cout%26lt;%26lt;"Enter the total number of students in each class \n";


cin%26gt;%26gt;num;


answer=num;


cout%26lt;%26lt;"What course you want to take\n":


cin%26gt;%26gt;name;


//function call


DisplayStudent(answer,num);


DisplayName(coursename%26amp;)


return 0;


}


//function goes here


void DisplayStudent(double num,double answer)


{


cout%26lt;%26lt;" the total number of students="%26lt;%26lt;answer;


}


voidDisplayName(coursename%26amp;)


{ cout%26lt;%26lt;"what course"%26lt;%26lt;answer;


cin%26gt;%26gt;course;


}





if u can help much appreciated !!!!!!!!!!

Pass by reference functions in C++?
#include %26lt;iostream%26gt;





using namespace std;





int calculateGPA(double, double);





void main ()


{





char[] course;


double totalCredits = 0.0;


double totalPoints = 0.0;


double hours, grade;


int continue = 1;





//1 equates to true in C or C++, 0 equates to false


while(continue)


{


cout%26lt;%26lt;"Enter class: ";


cin%26gt;%26gt;course;


cout%26lt;%26lt;"\nEnter credit hours: ";


cin%26gt;%26gt;(double)hours;


cout%26lt;%26lt;"\nEnter course grade: ";


cin%26gt;%26gt;(double)grade;





//add to total credits for GPA calculation


totalCredits += hours;


//this is tricky, I know this calculation because Im a student


//you should know this to from report cards


totalPoints += (grade * hours);





cout%26lt;%26lt;"\nEnter 1 to add another class or 0 to quit";


cin%26gt;%26gt;(int)continue;





}//end while





//once user quits entering info, calculate statistics


cout %26lt;%26lt; "GPA = " %26lt;%26lt; calculateGPA(totalPoints, totalCredits);





}//end main








int calculateGPA(totalPoints, totalCredits)


{


return (int)(totalPoints/totalCredits);


}
Reply:This should be your function prototype:





void DisplayName( string %26amp;courseName );





Keep at it!


Im having some compilerproblems in c++ its a very simple program im a complete noob to this pleace help?

#include %26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;string%26gt;


unsing namespace std:


int name()


{


string en //Employee name


hw, //Hours Worked


hr, //Hourly Rate


tw, //Total Wages


fe, //Federal Withholdings


sw, //State Withholdings


h, //Hospitalization


ud; //Union Dues


td; //Total Deduction


np; //Net Pay


cout%26lt;%26lt;fixed%26lt;%26lt;shouwpoint%26lt;%26lt;setprecision(...


cout%26lt;%26lt;"\nPlease enter Employee Name."%26lt;%26lt;endl;


cin%26gt;%26gt;en;


cout%26lt;%26lt;"\nPlease enter Hours Worked."%26lt;%26lt;endl;


cin%26gt;%26gt;hw;


cout%26lt;%26lt;%26lt;%26lt;\nPlease enter Hourly Rate"%26lt;%26lt;endl;


cin%26gt;%26gt;hr;


tw=hw*hr;


fw=(tw*18)/100;


sw=(tw*4.5)/100;


h=25.65;


ud=(tw*2)/100;


td=fw+sw+h+ud;


np=tw-td;


cout%26lt;%26lt;"Emplyee\t\t\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;...


cout%26lt;%26lt;"Hours Worked\t\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;hw%26lt;%26lt;endl;


cout%26lt;%26lt;"Hourly Rate\t\t\t\"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;hr%26lt;%26lt;\n\n;


cout%26lt;%26lt;"Deductions\n"


cout%26lt;%26lt;"Federal Withholdings\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;td%26lt;%26lt;endl...


cout%26lt;%26lt;"State Withholdings\t"%26lt;%26lt;":"%26lt;%26lt;setw(10)%26lt;%26lt;sw%26lt;%26lt;endl...


cout%26lt;%26lt;"Hospitalization\t"%26lt;%26lt;":"%26lt;%26lt;setw(1...

Im having some compilerproblems in c++ its a very simple program im a complete noob to this pleace help?
Hey what error compiler is giving??


How do you use pointers with two dimensional arrays in C++?

So I have this program that deals with one dimensional arrays. I want to expand it to two with array[row][col] how can I do this?





#include %26lt;iostream%26gt;


using namespace std;





int* getArray(int row);


void printArray(int* array, int row);





int main()


{


int row;


cout %26lt;%26lt;"Enter row length: ";


cin%26gt;%26gt;row;


int* array = getArray(row);


cout %26lt;%26lt; "array in main" %26lt;%26lt; endl;


printArray(array, row);


/*int* array2 = getArray();


cout %26lt;%26lt; "array2 in main" %26lt;%26lt; endl;


printArray(array2);


cout %26lt;%26lt; "array in main" %26lt;%26lt; endl;


printArray(array);


delete[] array2;*/


delete[] array;


return 0;


}





int* getArray(int row){


int *array = new int[row];


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


cout %26lt;%26lt; "Enter an integer: ";


cin %26gt;%26gt; array[i];


}


cout %26lt;%26lt; "array in getArray()" %26lt;%26lt; endl;


printArray(array, row);


return array;


}





void printArray(int* array, int row)


{


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


cout %26lt;%26lt; *(array+i) %26lt;%26lt; " ";


}


cout %26lt;%26lt; endl;


cout %26lt;%26lt; endl;


}

How do you use pointers with two dimensional arrays in C++?
Hi. I would love to help you. But, answering the question will be as long as your question. I thought that instead of giving a long answer, i could redirect you to some place where you can find good references.





http://www.cplusplus.com/doc/tutorial/


www.cplusplus.com/doc/tutorial/pointer...


www.codersource.net/c++_pointers.html





If you are still unable to find any useful information, and if there is anything specific that you would like to know, just drop in a mail to me. I shall try to help you.





Thanks! :)
Reply:u r goin right way baby
Reply:Generally speaking to access an array you use a for loop. This is for a 1 dimentional array. You want a two dimentional array.





So the way to do this is a nested for loop


ie.


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


for ( int j = 0; j %26lt; col, j++ ){


cout %26lt;%26lt; "Enter an integer: ";


cin %26gt;%26gt; array[i][j];


}


}





That is all there is to it. You already understand the array concept. Now go ahead and extend what you know.





Good luck.

secret garden

Please help with my C++ program...PLEASE?

I cant figure out how to properly output the days of the month, I need help with the first day of the year for the year inputed by the user? Help, please...





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;


using namespace std;





//function prototypes





int First_Day_Of_Month(int y, int m = 1);


int Number_Days_Of_Month(int y, int m);


bool IsLeapYear(int y);


void Print_Version();


void Print_Head(int y);


void Print_Month(int y, int m);


void Print_Month_Head(int m);





// Declare all variables


int firstday, number_days;


int year;


int Leapyear;





void main ()


{


Print_Version();


cin %26gt;%26gt; year;


Print_Head(year);





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


{


Print_Month(year, i);


}


cout %26lt;%26lt; "\nGoodbye! \n";


}





//Some Void Functions





void Print_Version()


{


cout %26lt;%26lt; "Please Enter any Year After 1753 \n";


}


void Print_Head(int y)


{


cout %26lt;%26lt; " " %26lt;%26lt; y %26lt;%26lt; endl;


}


void Print_Month(int y, int m)


{


Print_Month_Head(m);


firstday = First_Day_Of_Month(y,m);


number_days = Number_Days_Of_Month(y,m);


cout %26lt;%26lt; " ";





for (int k=0; k%26lt;firstday; k++)


cout %26lt;%26lt; " ";


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


{


cout %26lt;%26lt; setw(5) %26lt;%26lt; i;


if ((i + firstday)%7 == 0)


{


cout %26lt;%26lt; endl;


cout %26lt;%26lt; " ";


}


}


}


bool IsLeapYear(int y)


{


if (y%400 == 0)


{


return 1;


}


else if (y%4 == 0 %26amp;%26amp; y%100 != 0)


{


return 1;


}


else


return 0;


}


int First_Day_Of_Month(int y, int m)


{


firstday = (3/2 + (year) + (year / 4) -


(year / 100) + (year / 400) + 1) % 7;


return 2;


}


int Number_Days_Of_Month(int y, int m)


{


Leapyear = IsLeapYear(y);


if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)


{


return 31;


}


else if (m == 4 || m == 6 || m == 9 || m == 11)


{


return 30;


}


else if (Leapyear == 1)


{


return 29;


}


else


{


return 28;


}


}


void Print_Month_Head(int m)


{


if(m==1)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nJanuary\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==2)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nFebruary\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==3)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nMarch\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==4)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nApril\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==5)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nMay\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==6)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nJune\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==7)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nJuly\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==8)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nAugust\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==9)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nSeptember\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==10)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nOctober\nSun Mon Tue Wed Thu Fri Sat\n";


}


else if(m==11)


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nNovember\nSun Mon Tue Wed Thu Fri Sat\n";


}


else


{


cout%26lt;%26lt;"\n\n========================...


cout%26lt;%26lt;"\nDecember\nSun Mon Tue Wed Thu Fri Sat\n";


}


}

Please help with my C++ program...PLEASE?
Does your program even run? I copied and pasted it into my Dev C++ compiler and got lots of compilation errors:





int main(), not void main()





most of your text strings in your prints are not terminated. This might be due to the way Yahoo answers works. I do know that sometimes lines are truncated.
Reply:You need an array of generic 1st days of each month to start:





int day1month = [1,4,4,0,2,5,0,3,6,1,4,6];





there's a better algorithm, but I can only remember the parlor trick version so for dates 1900-2099 in pseudo code:


delyear = year-1900


datecycle = delyear % 7 (mod 7 that is)


leapdays = floor(delyear/4)


day1 = day1month[month-1] (if you use 1-12)


if year is a leap year and month is March or later add 1 to day1


first day of month = (datecycle+leapdays+day1)%7


0 = Sunday through 6=Saturday





I think this is off by 1 for each non-leap year century (1899 or after Feb 2100).





There is a more complete description and better method in one of Knuth's algorithm books, but it's at work. Also, you may want to return the value found as opposed to '2' as your First_Day_Of_Month function.