Friday, July 31, 2009

C++ game programming help?

I am using this tutorial to learn: http://www.cprogramming.com/tutorial/tut...





I copied the code onto my compiler, but it does not compile.


Is there a certain header file i need to use?





here's what's on my compiler:





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





void SetMCGA() {


_AX = 0x0013;


geninterrupt (0x10);


}





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


{


memset(vga, Col, 0xffff);


SetMCGA();


system("PAUSE");


return EXIT_SUCCESS;


}.

C++ game programming help?
It might be useful to know the compiling error...


C++ Programming...?

#include %26lt;iostream%26gt;





using namespace std;





void read(int a[], int n);


// read the first n elements of array a





bool sameValues(int a[], int b[], int size);


// compare two arrays of the same size


// It returns true if a and b contain the same values





const int SIZE = 5;





int main()


{





int list1[SIZE], list2[SIZE];





read(list1, SIZE);


read(list2, SIZE);





if (sameValues(list1, list2, SIZE))


cout %26lt;%26lt; "The two arrays contain exactly the same values." %26lt;%26lt; endl;


else


cout %26lt;%26lt; "The two arrays contain different values." %26lt;%26lt; endl;





cout %26lt;%26lt; endl;


system("pause");


return 0;


}





void read(int a[], int n)


{


int counter;


int list1[SIZE];





cout %26lt;%26lt; "Enter 5 values:" %26lt;%26lt; endl;


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


{


cin %26gt;%26gt; list1[SIZE];


}


}





bool sameValues(int a[], int b[], int size)


{


int list1[SIZE], list2[SIZE];





if (list1[SIZE]=list2[SIZE])


return true;


else return false;


}


My program is suppose to

C++ Programming...?
There are several problems with your sameValues function. See comments inline below:





bool sameValues(int a[], int b[], int size) {


//


// not an error, but in C++ we usually do this:


// for (int counter = 0; ...


//


int counter;


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


{ // extra, unnecessary block, i.e. { }


//


// The following 'if' statement sets


// a[SIZE] to b[SIZE], it does not compare


// the values at those locations. Also, you


// are indexing past the bounds of the arrays.


// The logic is wrong here too...


//


if (a[SIZE] = b[SIZE])


return true;


else return false;


//


// Something like this would be better:


// bool arraysMatch = true;


// for (int counter = 0; (counter %26lt; size) %26amp;%26amp; (arraysMatch == true); counter++) {


// arraysMatch = (a[counter] == b[counter]);


// }


// return arraysMatch;


//


// or, better yet, just a one line function:


// return (memcmp(a,b,size) == 0);


//


}


}
Reply:In both read and sameValues you have the input arrays named "a" and "b", but inside the function you are using "list1" and "list2" which are created new, assigned to, and then dropped when the function returns.





From read, remove the line "int list1[SIZE];" and change "cin %26gt;%26gt; list1[SIZE];" to "cin %26gt;%26gt; a[counter];".





From sameValues, remove "int list1[SIZE], list2[SIZE];". Change the if to test a[] and b[] instead of list1[] and list2[].





You also need a loop to test all of the values in the two lists, currently you would only be testing one value.





Hope this helps!


C++ question--how to write a program that searches a file of numbers and outputs the largest & smallest ones:?

This is what I have thus far...and now I am stuck. I don't understand the I/O streams very well...and I'm not sure what to do at this point. Any guidance is greatly appreciated :)





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main() {


int largest = 0;


int smallest = 0;


int testValue = 0;


ifstream inStream;





inStream.open("integers.txt");


if (inStream.fail())


{


cout %26lt;%26lt; "Input file opening failed.\n";


exit(1);


}





char next;


inStream.get(next);


while (! inStream.eof())


{


cout %26lt;%26lt; next;


inStream.get(next);


}





inStream.close();





cout %26lt;%26lt; "The largest integer is: " %26lt;%26lt; largest %26lt;%26lt; endl;


cout %26lt;%26lt; "The smallest integer is: " %26lt;%26lt; smallest %26lt;%26lt; endl;





return 0;


}


// function main

C++ question--how to write a program that searches a file of numbers and outputs the largest %26amp; smallest ones:?
Ahh, it's been a long time since I programmed in C++... Let's see... You're almost there, provided the syntax is correct...





A few things... Why is next a char? I thought you wanted to be reading numbers from the file, not characters?





Second - read the first number before the loop and assign it to both largest and smallest. Because it will be both largest and smallest, if it's the first one... Then use two if's inside the loop to compare the number you just read to largest, and see if it's larger then assign its value to it... Respectively with the smallest....





And that should be about it....





I would've modified your code and posted it... but it's your homework, right? So it's better if you do it....





LEM.
Reply:You will want to use the %26gt;%26gt; operator in a loop, as in:





inStream %26gt;%26gt; testValue; // reads testValue from inStream


// do tests to set smallest and largest





It works the same way that you would use it with cin. Note that this will fail if the file is not formatted correctly for the type (in this case, int).


C++ Arrary that finds the MAXNUM?

hey guys. so Im having problems with this code. I know I'm close but my program cash's every time after entering a number. I need to find the max num as each number is inputed. I can only use one loop.





hers what I have:





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int MAXELS = 1000;


int i, max, nums[MAXELS];





cout %26lt;%26lt; "Enter a series of numbers: ";


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





max = nums[0];








for (i=1;i%26gt;MAXELS;i++)


if (max %26lt; nums[i])


max = nums[i];





cout %26lt;%26lt; "the max num is" %26lt;%26lt;max %26lt;%26lt;endl;








system("PAUSE");


return 0;


}





any ideas?

C++ Arrary that finds the MAXNUM?
Your index needs to go from 0 to i%26lt;mexels





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





--------------------------------------...





also


cout %26lt;%26lt; "Enter a series of numbers -1 to stop: ";


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





Try:


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


{


cout %26lt;%26lt; "Enter a series of numbers: ";


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


if(i == -1)


i=mexels;


}

nobile

C++ program help - using <time.h> - answer within 6 hours please!?

This is the program:





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


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





using namespace std;





const char *get_greet();





int main(int argc, char **argv)


{


if(argc%26lt;2)


{


cout %26lt;%26lt;"please enter name" %26lt;%26lt; endl;


}


cout %26lt;%26lt; get_greet() %26lt;%26lt; " " %26lt;%26lt; argv[1] %26lt;%26lt; "!" %26lt;%26lt; endl;





return 0;


}








The questions are:





1. Write pseudo code illustrating the logic you will have in the function get_greet





2. If definition of get_greet was "void get_greet(char *buffer, int size)", what are the changes you have to do to main() to get it working?











Any help is appreciated.


Thank you so much

C++ program help - using %26lt;time.h%26gt; - answer within 6 hours please!?
Looks to me like get_greet returns a greeting specific to the time of day, so if hours %26lt; 12 it would be "Good Morning" or if hours%26gt;18 "Good Evening." Why don't you open up your time.h header file or look up the documentation elsewhere (I use GCC. They kind of EXPECT you will open and read your header files if you want to use them properly).





The answer to number two seems obvious but if this is homework believe me, we are doing you no favor by answering that question.





EDIT: Okay, the point would be you would want to extract hours from an asctime() string. I've added a discussion of it in sources. The asctime() string is a fixed-length string, so you simply go to the place where hours start, extract that and the next char, convert them to an integer (probably using itoa() which means storing them in a 3-char string and making the third char '\0') and going from there.





The answer to your second question of course is in theory you can just do a cout %26lt;%26lt; get_greet(buffer, SOME_SIZE) %26lt;%26lt; " " %26lt;%26lt; argv[1] %26lt;%26lt; "!" %26lt;%26lt; endl; assuming SOME_SIZE is #defined up above as the maximum number of chars to put in buffer and buffer is defined as a block of memory which is large enough to hold enough chars. {Incidently, I tend to send printf and cout ' ' and '!' rather than " " and "!" because when you use single quotes it sends chars but when you use double quotes it sends a two char array with the second char being'\0'. I know it doesn't save a lot but I've been questioned about why my code compiles smaller than some other peoples}.





You CAN do the above. It will evaluate get_greet(buffer, SOME_SIZE). It may be easier for you if you execute that above the cout statement and then just send it buffer.





Again, you either have to declare buffer as an array of fixed size, or allocate enough memory using malloc and remember to free it before exiting. And of course you can send get_greet a variable or a const or a digit, but the advantages of #defining a SOME_SIZE are if you have to use it elsewhere in the program you change it once -- while the program gets no chance to change it as the preprocessor will substitute whatever number is there for every occurance of SOME_SIZE, and with the right name people will know exactly what it is for.





Is that helpful?
Reply:Don't get me wrong here. But doing these yourself are excellent ways to begin to understand C/C++ functions.


C++ a loop with string.erase !?

I want to get rid of all numbers in my sentence. This only gets rid of hte first number. What am I doing wrong in the loop?








#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;





int main()


{


string myString="I have 24 bananas.";


size_t len = myString.length();





size_t i=0;


while (i%26lt;len)


{


if ( isdigit(myString[i]) )


(myString.erase(i,1));


++i;


}


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


return 0;


}

C++ a loop with string.erase !?
The other answers are generally on mark but the bottom line is that this is not the best erase() method to use in that kind of loop.





myString.erase(i, 1) actually returns a new string reference. You are ignoring the return value but the underlying string has still changed. You have to be careful with stl containers (which include std::string) that the container and its iterators aren't invalidated with operations that mutate the state.





I think the single iterator form of string::erase() is a better choice for what you are doing. Something like:





string::iterator it = myString.begin();





while (it != myString.end())


{


if (isdigit(*it))


it = myString.erase(it);


else


it++;


}
Reply:The 2 and 4 are beside each other. When you erase the letter, all letters after that are shifted back a space. You're saying ++i so it skips one. It's a bit dificult to explain but you'll see it happen if you use:


cout %26lt;%26lt; myString[i];





Basically, fix it by saying:


if ( isdigit(myString[i]) )


{


(myString.erase(i,1));


i -= 2;


}


++i;








I think you might get away with simply --i but I'm not sure. Hope that helps :)
Reply:I have updated the code to properly erase all digits





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;





int main()


{


string myString="I have 24 bananas.";


size_t len = myString.length();





size_t i=0;


while (i%26lt;len)


{


if ( isdigit(myString[i]) )


(myString.erase(i,1)); // erase one character, leave 'i' alone.


else //* This is what I added *//


++i; // advance to next character


}


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


return 0;


}


C++ help???

i want to fix the errpr and make the program run


#include%26lt;iostream%26gt;


using namespace std;


double sum( double * begin, double * end) {


double *p = begin;


double result = 0;


while (p != end) {


result += *p++;


}


return result;


}


int main()


{


double *first,*last;


cout%26lt;%26lt;"enter the begin of the array \n";


cin%26gt;%26gt;* first;


cout%26lt;%26lt;"enter the last item in the array \n";


cin%26gt;%26gt;* last;


cout%26lt;%26lt;sum(* first,* last);


system("pause");


return 0;


}

C++ help???
#include%26lt;iostream%26gt;


using namespace std;


double sum( double * begin, double * end) {


double *p = begin;


double result = 0;


while (result %26lt; *end) { // %26lt; end


result += *p+result;


}


return result;


}





int main()


{


double first,last;


cout%26lt;%26lt;"enter the begin of the array \n";


cin%26gt;%26gt;first;


cout%26lt;%26lt;"enter the last item in the array \n";


cin%26gt;%26gt;last;


cout%26lt;%26lt;sum(%26amp;first,%26amp;last);


system("pause");


return 0;


}


C++ error!!!!?

this program get the size if an array , i want to fix the error


#include%26lt;iostream%26gt;


using namespace std;


int main()


{


int arr[5]={1,2,3,4,5};


int * begin,*end;


begin=arr[0];


end=arr[5];


return begin-end-1;


system("pause");


return 0;


}

C++ error!!!!?
There are a few problems here.





arr[0] = the contents of the first element of the array, not its address. You need to set begin to either arr, or %26amp;arr[0].





arr[5] indexes outside the bounds of the array. I can't tell you what its value is, but you shouldn't be referencing there. Set end to %26amp;arr[4].





The address of the beginning of the array is less than the address of second, and subsequent, elements of the array. So your statement: begin - end - 1, will be a negative value.





I guess you want to use pointers, or array addresses, to compute the size. Your code should look something like this:





#include %26lt;iostream%26gt;





using namespace std;





int size(int *begin, int *end);





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


int a[] = {1,2,3,4,5};


int len = sizeof(a) / sizeof(*a);





cout %26lt;%26lt; "num elements in a = " %26lt;%26lt; len %26lt;%26lt; endl;


cout %26lt;%26lt; "size(a) = " %26lt;%26lt; size(a,%26amp;a[len-1]) %26lt;%26lt; endl;


}





int size(int *begin, int *end) {


return end - begin + 1;


}
Reply:This program doesn't make any sense. What have you been trying to achieve ?





The size of the array in elements is calculated as


sizeof(arr)/sizeof(int).





If you wanted address of the first and last elements, it would be %26amp;arr[0] and %26amp;arr[4] (not 5).





system("pause") will not be executed because you terminate the program by "return" before that.

flower girl dresses

C++.im supposed to display the initials of the names. but it doesnt work.what hav i done wrong..pls help!?

#include%26lt;iostream%26gt;





using namespace std;





int main()


{


char firstinitial, middleinitial, lastinitial;





cout%26lt;%26lt;"please enter your first name:"%26lt;%26lt;endl;


cin.get(firstinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"Please enter your middle name:"%26lt;%26lt;endl;


cin.get(middleinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"please enter your last name:"%26lt;%26lt;endl;


cin.get(lastinitial);


cin.ignore(100, ' ');


cout%26lt;%26lt;"the initial of all three names are: ";


cout%26lt;%26lt;firstinitial%26lt;%26lt;middleinitial%26lt;%26lt;las...





return 0;


}

C++.im supposed to display the initials of the names. but it doesnt work.what hav i done wrong..pls help!?
Why are you using cin.ignore() ?


C++ Program Question?

The question is:





Write a complete program that reads in some unknown number of positive integers from standard input (keyboard) into a vector. Then output all values to standard output (terminal) in reverse order (with one space between each value). The user will type a -1 to signal that they are through inputting positive integers. Do not output the -1.


For example, if the values read in are in this order: 1 3 5 2 9 then the output would be: 9 2 5 3 1


Do not output anything other than the values in the vector. In other words, do not prompt the user for input. Just assume the user knows to input some number of positive integers and a -1 to finish.





This is my code:





#include %26lt;vector%26gt;


#include %26lt;iostream%26gt;


using namespace std;





int main()


{


vector%26lt;double%26gt; Vec;


int vec_size = 0;


while (Vec[vec_val = -1)


{


cin %26gt;%26gt; Vec[vec_val];


vec_val ++;


}


for(vec_size; vec_size %26gt;= 0; vec_size--) cout %26lt;%26lt; Vec[vec_size] %26lt;%26lt; " ";


return 0;


}

C++ Program Question?
#include%26lt;vector%26gt;


#include%26lt;iostream%26gt;





using namespace std;


double val = 0;


vector%26lt;double%26gt; vec;


while(val != -1){





cin %26gt;%26gt; val;





vec.push_back(val);


};





int reverse_index = vec.size() -1;





vector%26lt;double%26gt; reverse(vec.size(), 0);





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





reverse[reverse_index--] = vec[i];





};





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





cout %26lt;%26lt; reverse[i];


};





return 0;





}











you don't even have to copy them if you don't want to you can just do








for(int i = vec.size() -1; i %26gt; 0; --i){





cout %26lt;%26lt; vec[i];





};














vectors have a bunch of built in functions such as size() push_back()....





check em out


http://www.cppreference.com/cppvector/in...


C++, lowest test score drop question?

Writing a program where user inputs 5 scores %26amp; lowest score drops. Has to be in 2 seperate functions. I have getValue function done ok; user inputs 5 scores as array of type float. When I move on to the second function (findLowest), I don't know how to transfer the scores found in getValues. No global variables, %26amp; I think I'm supposed to use call by reference, but I'm confused at how you would take the array from getValues and do a call by reference to get the scores into findLowest.





# include %26lt;iostream%26gt;


using namespace std;





void getValues();


void findLowest();








int main()


{


getValues();


findLowest();


return 0;


}





void getValues()


{


const int size = 5;





float score[size];





cout%26lt;%26lt; "Enter " %26lt;%26lt; size%26lt;%26lt; " scores, seperated with a space: \n";


cin%26gt;%26gt; score[0];





findLowest();


}





void findLowest()


{


int i;


float lowscore;





lowscore = score[0];


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


{


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


if (score[i] %26lt; lowscore)


lowscore = score[i];


}

C++, lowest test score drop question?
As soon as getValues() returns, the score array gets deleted. What you need to do is create an array in the main() method (this isn't a global variable) and pass it to getValues() and findLowest() (c++ will automatically pass arrays by value).





int main()


{


float highscores[4];


getValues(score);


return 0;


}





void getValues(float[ ] highscores)


{


float scores[5];





// Populate the the scores array


// i.e. scores[ i ] = input





float lowscore = findLowest(scores);





//move high scores into highscores array


int count=0;


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


{


if (scores[i] != lowscore) // as long as it's not the low score


highscores[count++] = scores[i];


}





}








float findLowest(float[ ] scores)


{


// Run your algorithm to find the lowest score in scores[ ]


// return that score


}





That's how it's done. Just fill in the blanks. Good luck!


C++ help please?

im making a text editor please look at the code and tell me my problem thanks.





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


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


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


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


using namespace std;





int main()


{


system("@echo off");


cout %26lt;%26lt; "1. create a file \n 2. open file";


int choice;


cin %26gt;%26gt; choice;


switch (choice) {


case 1 :


int fname;


cout %26lt;%26lt; "filename and location.";


cin %26gt;%26gt; fname;


ofstream file;


file.open(fname);


file.close();


cout %26lt;%26lt; "how many lines do you want in the file?";


int lines;


cin %26gt;%26gt; lines;


if (lines = 1){


char lineA;


cin %26gt;%26gt; lineA;


}


if (lines = 2){


char lineA;


cin %26gt;%26gt; lineA;


char lineB;


cin %26gt;%26gt; lineB;


}


if (lines = 3){


char lineA;


char lineB;


char lineC;


cin %26gt;%26gt; lineA;


cin %26gt;%26gt; lineB;


cin %26gt;%26gt; lineC;


}


if (lines = 4){

C++ help please?
Here's one problem:


The if checks are assigning lines to a number instead of comparing lines to a value.





change " if(lines = 1) " to " if(lines == 1) "


and change that for every if check.

flower garden

C++ Monty Hall problem?

#include%26lt;iostream%26gt;


#include%26lt;cstdlib%26gt;


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





using namespace std;





const int NUM_GAMES = 10000;


int prizedoor;


int playerguess;


int revealdoor;


int newguessdoor;


int i;





int play_game_no_switch()


{


prizedoor = rand() % 3;


playerguess = rand() % 3;


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


return 0;


}


int play_game_switch()


{


prizedoor = rand() % 3;


playerguess = rand() % 3;


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


{


if((i!=prizedoor) %26amp;%26amp; (i!=playerguess))


{


revealdoor = i;


}


}


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


{


if ((i!=revealdoor) %26amp;%26amp; (i!=playerguess))


{


newguessdoor = i;


}


}


if (newguessdoor == prizedoor) return 1;


return 0;


}


int main()


{


int numWinsSwitch = 0;


int numWinsNoSwitch = 0;


int i;


srand(time(NULL));


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


{


numWinsNoSwitch += play_game_no_switch();


numWinsNoSwitch += play_game_switch();


}


This is the first part of my code, the rest of them is fine, when I run it, the program says I won 0 time and lose 10000 time by switching..

C++ Monty Hall problem?
add return 0; to the end of main()





I'm surprised your play_game_no_switch doesn't give a compile error. You have a for loop that is unclosed, which means all it's doing is this:


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


return 0;


}


I can't figure out what you were trying to do there. Get rid of it completely. The way it is now, it ALWAYS returns 0. You have to add a check before you return:





if( playerguess == prizedoor ) return 1;


return 0;








I don't know if the random number generation is correct because I barely ever use it, but I'll take your word for it.





In main(), you have this:





numWinsNoSwitch += play_game_no_switch();


numWinsNoSwitch += play_game_switch();





Your using the same variable (numWinsNoSwitch) for both styles of play. You need to use numWinsSwitch for the second one. That's why it's giving you 0 for both. Your 'noSwitch' game always loses because it always returns 0. Then you try to play the 'switch' game, and the variable you store the results in is a different one than you are printing out.





Fix those problems and if it still doesn't work, give more information about what's still wrong.


Help me in enumerating specific network member computers in C++ or C#...?

Hello and thank you about your attention to my question.





I want to enumerate a specific network member computers by a .NET 2.0 or MFC based application. How can I do that from a member computer of the network?





Please tell me which namespace or class I should use...





Be Succeed,


Babax.

Help me in enumerating specific network member computers in C++ or C#...?
I'm a bit busy right now but i believe you could do a standard "broadcast" mesage out across the network and those alive will respond back...or you could do a "ping" on each host on the network based on your addy...you'd need to use the subnet mask to determine the host portion and then just iterate through each up to 254 and see who responds back....it wont tell you all the computers across the network, just the computers within the mask (potentially up to 255 computers).......


When I compile my C++ code in linux, this error is printed: "no such file or directory",?

the error belongs to these lines:


#include %26lt;iostream%26gt;


using namespace std;


#include %26lt;vector%26gt;

When I compile my C++ code in linux, this error is printed: "no such file or directory",?
Maybe the setup your compiler is wrong.





patch up this codes, if you can run this then your compiler is working.





#include %26lt;iostream%26gt;


using namespace std;





int main()





{


cout %26lt;%26lt; "Hello World" %26lt;%26lt; endl;





return 0;





}





Note : your headers format is wrong, this the correct one.





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;





using namespace std; // always after all the headers otherwise you will use %26lt;vector.h%26gt; with "h" extension.
Reply:check to make sure you have those files. sometimes when folks build their linux box, the forget to install the headers for development. try doing a search for those files
Reply:check that all files and directories you are referrencing actually exist. I don't think vector is correct. read your documentation that came with the compiler.


How to eliminate Visual C++ unresolved external symbol error???

Compiling...


hello.cpp


Linking...


LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16


Debug/hello.exe : fatal error LNK1120: 1 unresolved externals


Error executing link.exe.





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


======================================...


\\The following is the source code








#include %26lt;iostream%26gt;





using namespace std;





int main(){


cout %26lt;%26lt; "Hello" %26lt;%26lt; endl;


return 0;


}


======================================...





What is that annoying error????


I copied the code and pasted it in DevC++, it had no problem running.





Sometimes, I re-create a new project and paste the code there, the error sometimes disappers and comes back again.

How to eliminate Visual C++ unresolved external symbol error???
just have a look at the link....





hope it helps!

edible flowers

C++ help??

I am trying to figure out where I would input these numbers in the code so I can compile it.


#include %26lt;iostream%26gt;


using namespace std;





int main() {


int x;


while (cin %26gt;%26gt; x) {


for (int i=x; i%26gt;0; i--) {


cout %26lt;%26lt; '*';


}


cout %26lt;%26lt; endl;


}


return 0;


}


What would this program print with input 1 3 5 1 3 5?

C++ help??
What are you talking about? You can't plug the numbers into the code to see what it does. Pay attention to where the input is: in the while line.





The output is:


*


***


*****


*


***


*****





Can you see why? Look at the for loop and the way the blocks are nested. Indenting the code properly might help.
Reply:You may contact a C++ helper live at website like


http://gionram.com/
Reply:you can download a C++ compiler called Dev-C++ from bloodshed.net at http://www.bloodshed.net/dev/devcpp.html


If you ran this program and typed in 1 3 5 1 3 5 it would output





*


***


*****


*


***


*****





Hope this helps.


C ++ help anyone please!!! i am getting this error: Error 1error C2108: subscript is not of integral type?

first of all i don't quite undurstand the problem....this is the problem:


The Federal Reserve wants a program that can give the average interest rate on mortgages using data from four nationally ranked banks. Your tasks are to create a program that calculates the average of values stored in a one-dimensional double array named rates. The program should display the average rate on the screen.


Use the following data to:


Bank of America 6.2%, RBC Centura 7.1%, BB%26amp;T 5.9%, Federal Credit Union 6.0%





this is my code:


#include %26lt;iostream%26gt;





using namespace std;





int main()


{


//declare array


double total = 0;


double average = 0;


double rate[4] = {6.2, 7.1, 5.9, 6.0};








// calculate sum


for (double x = 0; x %26lt; 4; x = x + 1)


total = total + rate[x];


//end for





//calculate and display average


average = total / 4;





cout %26lt;%26lt; "Average: " %26lt;%26lt; average %26lt;%26lt;endl;


return 0;


}/





is it right? what i am doing wrong?i am just a beginner help me please!!

C ++ help anyone please!!! i am getting this error: Error 1error C2108: subscript is not of integral type?
X is the subscript, so x has to be an integer. Computers treat integers, floats and doubles differently so NEVER use a float or a double as an integer unless the computer has been treating you horribly -- and even then, obviously, you will only be torturing it for a few nanoseconds until the compiler catches you.





Change it to:


for (int x=0; x%26lt;4; x=x+1)
Reply:You cannot use a non-integral datatype as a subscript; you need to use the int datatype. For example:


// calculate sum


for (int x = 0; x %26lt; 4; x = x + 1)


total = total + rate[x];


//end for
Reply:check this out. i have the book in my hands right now. want me to get back to u? u can trust me dude i have the book in my hands .








(im a computer nerd)
Reply:Double types are not integer. They're floating point. You can't use a floating point number as a subscript.





Hope that helps.
Reply:I'll tell you the real answer without me telling you I'm a computer nerd. Change this line from double to int.





for (int x = 0; x %26lt; 4; x = x + 1)


C++ Strings?

Okay i would like to pull a computer ID from Net View using strings. What i have so far is:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





char A;





using namespace std;





int main (){


system("net view") = A


string str1( A , 11, 4 );


}


however, I can't seem to store new view as a variable.

C++ Strings?
int main (){


A = system("net view")


string str1( A , 11, 4 );


}





you were having system(netview) get the empty variable A.. flip it around and it should work


C++ problem?

i'm having trouble trying to get to program to work...


i have to generate random numbers between 0 - 10...


and then if the user doesn't enter the correct number then it hints the user to guess higher or lower.


also the program will not end until the user types the correct number.





this is what i have...





#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


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


using namespace std;


int main()


{


time_t seconds;





time(%26amp;seconds);





srand((unsigned int) seconds);





cout %26lt;%26lt; "Enter a number (0-10): " %26lt;%26lt;endl;


cin %26gt;%26gt; guess;





if(guess%26lt;rand)


{


cout%26lt;%26lt;"Guess higher: "%26lt;%26lt;endl;


cin %26gt;%26gt;guess;


}


if(guess%26gt;rand)


{


cout %26lt;%26lt;"Guess lower: "%26lt;%26lt;endl;


cin%26gt;%26gt;guess;


}


if(guess=rand)


{


cout%26lt;%26lt;"you are Correct!!"%26lt;%26lt;endl;


}





return 0;


}








what am i doing wrong??

C++ problem?
You aren't defining the variable that holds the random number. Something like this will generate a random number between 0 and 10:





int r = rand() % 11;





The whole guessing part should be inside a loop that continues until the guess equals the random number.
Reply:You are not enclosing your "ifs" for determining a correct answer on a loop. You need a "while" loop and if the guess is correct, you need to call "break".





As written, your code will only go through one pass.
Reply:Try this:





#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


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


using namespace std;


int main()


{


time_t seconds;





time(%26amp;seconds);





srand((unsigned int) seconds);





int guess;


cout %26lt;%26lt; "Enter a number (0-10): " %26lt;%26lt;endl;


cin %26gt;%26gt; guess;





int nRand = rand() % 11; // not the best way of restricting the range, as the distribution will now be skewed, but good enough for a simple program like this





while (guess != nRand)


{


if(guess%26lt;rand)


{


cout%26lt;%26lt;"Guess higher: "%26lt;%26lt;endl;


cin %26gt;%26gt;guess;


}


if(guess%26gt;rand)


{


cout %26lt;%26lt;"Guess lower: "%26lt;%26lt;endl;


cin%26gt;%26gt;guess;


}


}





cout%26lt;%26lt;"you are Correct!!"%26lt;%26lt;endl;


}





return 0;


}

covent garden

C++ Question?

I need to write a program that takes characters (only alphabetical) input from the screen (ended with a period), puts them into an array, keeps count of how many there are of each character and prints out a list of the characters and their number of occurrences, sorted by their occurrence, highest to lowest. The main thing I don't know how to do is to sort the characters based on their occurrence and also the counting itself isn't completely working. Can anyone else correct this code?





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





int main(void)


{


using namespace std;





char chars[]="abcdefghijklmnopqrstuvwxyz";


int i;


int count[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...





char inp;





cin%26gt;%26gt;inp;





while(inp !='.')


{


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


{


if(inp==chars[i])


count[i]++;


}


cin%26gt;%26gt;inp;


}





cout%26lt;%26lt;"Character Count"%26lt;%26lt;endl;





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


{


if(count[i]!=0)


{


cout%26lt;%26lt;chars[i]%26lt;%26lt;" "%26lt;%26lt;count[i]%26lt;%26lt;endl;


}


}





system("pause");





return 0;


}

C++ Question?
If you don't understand some of the concepts involved you should read up on them. Ask questions if necessary.








#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;


#include %26lt;algorithm%26gt;





using namespace std;





struct elementType


{


char letter;


int count;





elementType(char l, int c) : letter(l), count(c) {};


};





bool compare(elementType a, elementType b )


{


return(a.count %26gt; b.count);


}





typedef vector%26lt;elementType%26gt; Array;








int main(void)


{


//creat vector of letter/count elements


Array array;





for (char i = 'a'; i %26lt;= 'z'; ++i)


{


elementType e(i, 0);


array.push_back(e);


}





//collect input chars


char inp;


cin %26gt;%26gt; inp;





while (inp !='.')


{


if ((isalpha(inp))


%26amp;%26amp; (islower(inp)))


array[inp - 'a'].count++;





cin %26gt;%26gt; inp;


}





//sort array


sort(array.begin(), array.end(), compare);





//spit out results





cout %26lt;%26lt; "Character Count" %26lt;%26lt; endl;





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


{


if (array[i].count %26gt; 0)


{


cout %26lt;%26lt; array[i].letter %26lt;%26lt; " " %26lt;%26lt; array[i].count %26lt;%26lt; endl;


}


}





system("pause");





return 0;


}
Reply:Convert the user input to an ascii value. Make a dummy array the same length as the user input array. Then all you have to do is.





for(int index=0; index%26lt;userInput.length();index++)


dummy[int(userInput[index])]++;





Print it out


for(int index=0; index%26lt;userInput.length();index++)


{


if(dummy[index]%26gt;0)


cout %26lt;%26lt; "The letter " %26lt;%26lt; char(index) %26lt;%26lt; "occured" %26lt;%26lt;dummy[index] %26lt;%26lt; " times" %26lt;%26lt; endl;


}
Reply:Seems like less work to use a map





You get the letter, increment the int.





Create some iterators and use the sort algorithm.
Reply:First, your while loop probably doesn't work because you need to get an index of inp. Something like:





int idx = 0;


while (inp[idx] != ".")


{


...


...


...


idx++;


}





Second, there are much better ways to add to the count than the following, but it should still work:





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


{


if(inp==chars[i])


count[i]++;


}





Lastly, you then need to sort. To do that, you might want to replace count with a struct that's made up of a character (the letter of the alphabet) and an integer (which is the count). Then do something simple like a bubble sort on it (you can google that).





Overall, there are better/easier ways to do this, but if you want to use your code as a starting point, then you need to look at these three areas.


C++ Help! How can I modify my program!?

I have to rewrite my program so that it prompts the user to enter the name of the file to be read, instead of reading the source file itself. This is my program:





#include %26lt;fstream%26gt;


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





int main()


{


ifstream fin;


fin.open("readFile.cpp");


if (!fin.good()) throw "I/O error";





while (true)


{


if (!fin.good()) break;





string lineFromFile;


getline(fin, lineFromFile);


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


} // while


fin.close();





return 0;


} // main

C++ Help! How can I modify my program!?
Make a string, called String someString. prompt the user for that string using getline instead of cin because cin ignores whitespace and you might encounter a space in the file name. Replace fin.open("readFile.cpp") with fin.open(someString).

email cards

C++ programing problem regarding procedure function?

#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include "Point.h"


using namespace std;





void rotate(Point p, double angle)


{


double new_x = ((p.get_x()*cos(angle))+(p.get_y()*sin(a...


double new_y = ((-(p.get_x())*sin(angle))+(p.get_y()*co...


double dx = p.get_x()- new_x;


double dy = p.get_y()- new_y;


p.move(dx,dy);


}


void scale(Point p, double scale)


{


double new_x = scale * p.get_x();


double new_y = scale * p.get_y();


double dx = p.get_x()- new_x;


double dy = p.get_y()- new_y;


p.move(dx,dy);


}





int main()


{





cout%26lt;%26lt; "The original point p (5,5) rotated 5 times by 10 degrees then scaled 5 times by .95 is:""\n";


Point p(5,5);


double angle = 10;


double scale = .95


int rotation_count = 0;


int scale_count = 0;





while (rotation_count%26lt;5)


{


void rotate(Point p, double angle);


cout%26lt;%26lt; "The point is now" %26lt;%26lt; p.get_x() %26lt;%26lt; " " %26lt;%26lt; p.get_x()%26lt;%26lt; "\n";


rotation_count++;


}


return 0;


}

C++ programing problem regarding procedure function?
You'll need to change the function signature of rotate from


void rotate(Point p, double angle)


to


void rotate(Point%26amp; p, double angle)





as p needs to be passed by reference. The function scale(...) seems to have the same problem and can be corrected in the same way.





Also, line 47 should be


rotate(p, angle);


(this is how you call a function in C/C++).





Hope this helps.
Reply:while (rotation_count%26lt;5)


{


rotate(Point p, double angle);


cout%26lt;%26lt; "The point is now" %26lt;%26lt; p.get_x() %26lt;%26lt; " " %26lt;%26lt; p.get_y()%26lt;%26lt; "\n";


rotation_count++;


}


return 0;


}


C++ programing problem regarding procedure function?

#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include "Point.h"


using namespace std;





void rotate(Point p, double angle)


{


double new_x = ((p.get_x()*cos(angle))+(p.get_y()*sin(a...


double new_y = ((-(p.get_x())*sin(angle))+(p.get_y()*co...


double dx = p.get_x()- new_x;


double dy = p.get_y()- new_y;


p.move(dx,dy);


}


void scale(Point p, double scale)


{


double new_x = scale * p.get_x();


double new_y = scale * p.get_y();


double dx = p.get_x()- new_x;


double dy = p.get_y()- new_y;


p.move(dx,dy);


}





int main()


{





cout%26lt;%26lt; "The original point p (5,5) rotated 5 times by 10 degrees then scaled 5 times by .95 is:""\n";


Point p(5,5);


double angle = 10;


double scale = .95


int rotation_count = 0;


int scale_count = 0;





while (rotation_count%26lt;5)


{


void rotate(Point p, double angle);


cout%26lt;%26lt; "The point is now" %26lt;%26lt; p.get_x() %26lt;%26lt; " " %26lt;%26lt; p.get_x()%26lt;%26lt; "\n";


rotation_count++;


}


return 0;


}

C++ programing problem regarding procedure function?
You'll need to change the function signature of rotate from


void rotate(Point p, double angle)


to


void rotate(Point%26amp; p, double angle)





as p needs to be passed by reference. The function scale(...) seems to have the same problem and can be corrected in the same way.





Also, line 47 should be


rotate(p, angle);


(this is how you call a function in C/C++).





Hope this helps.
Reply:while (rotation_count%26lt;5)


{


rotate(Point p, double angle);


cout%26lt;%26lt; "The point is now" %26lt;%26lt; p.get_x() %26lt;%26lt; " " %26lt;%26lt; p.get_y()%26lt;%26lt; "\n";


rotation_count++;


}


return 0;


}


C Language keep getting an error?

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


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


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


#include%26lt;cmath%26gt;


using namespace std;








int main();











{float x1,x2,y1,y2; ***** I get a error C2447: '{' : missing function header (old-style formal list?) For this line





float d;


x1=26; y1=80;


printf("Enter Hurricane Latitude")


scanf("hurricane Latitude")





scanf_s("%f, %f, %f, %f",%26amp;x1,%26amp;x2,%26amp;y1,%26amp;y2);


d=sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));


printf("%f",d);


getch();


return 0;

C Language keep getting an error?
Some Semicolons are missing on the printf and scanf.





Do you get this error using those libraries in other programs?
Reply:First remove the semicolon after the main function.


int main()


{


//function body goes here...


}


next put a semicolon after printf() call


printf("Enter Hurricane...Latitude");


your scanf call is not correct... I dont know what you are scanf() ing otherwise i would have told you what to do...


put a closing flower bracket after return 0;


}


remove ***** I get a error C2447: '{' : missing function header (old-style formal list?) For this line


C++ modify program?

i need it to stop when uncut=total my orginal prog. is





#include%26lt;cmath%26gt;


#include%26lt;string%26gt;


#include%26lt;iostream%26gt;





using namespace std;





int main()


{





double total, uncut;


const double restrate=.02;





total = 14000;


uncut = 2500;





cout %26lt;%26lt; "Year..............Acres" %26lt;%26lt; endl %26lt;%26lt; endl;





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


{


cout %26lt;%26lt; k+1 %26lt;%26lt; ".............." %26lt;%26lt; uncut %26lt;%26lt; endl;





uncut += restrate * uncut;


}





getchar();





return 0;


}

C++ modify program?
if(uncut==total) break;
Reply:add this line after uncut += restrate * uncut;





if (uncut==total) return 0;

cheap flowers

Trying to reverse name C++ here is what I have so far... (from reverse sentence lab)?

ok first off how to I define the string to stop at a comman ","? thanks





~Dan~





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;








int main()


{


//Local constants


const char SENTINEL = ',';





//Local variables


string wholename;


int length;


int comma;


string firstname;


string lastname;


string finalname;


int counter;


string rS;














//Input ten numbers


cout%26lt;%26lt;"Enter your name (Last, First): " %26lt;%26lt;endl;


getline(cin, wholename, '\n');





//Compute average


length=length-comma;


for (counter=(comma+2); counter%26gt;=0; counter--)


{


rS+=wholename[counter];


}


firstname = firstname - SENTINEL








//distance


cout%26lt;%26lt;"Your name reversed is: " %26lt;%26lt;endl;


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











//Indicate to OS succesful termination of program


return 0;





} //End main








ok first off how to I define the string to stop at a comman ","

Trying to reverse name C++ here is what I have so far... (from reverse sentence lab)?
Actually, why aren't you using what is already built into std::string? Something like:





#include %26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


#include %26lt;string%26gt;





using namespace std;





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


{


string wholename, firstname, lastname;





cout%26lt;%26lt;"Enter your name (Last, First): " %26lt;%26lt;endl;





getline(cin, wholename, '\n');





size_t commaPos = wholename.find(',');





if (commaPos == string::npos) //no comma in str


{


cout %26lt;%26lt; "invalid input\n";


exit(EXIT_FAILURE);


}





firstname = wholename.substr(commaPos + 1, wholename.length() - 1);


lastname = wholename.substr(0, commaPos);





cout %26lt;%26lt; firstname %26lt;%26lt; " " %26lt;%26lt; lastname %26lt;%26lt; endl;





return(EXIT_SUCCESS);


}
Reply:Why arent you using a simple stack?
Reply:First off this code will not compile. Comma and Length are not initialized, meaning they don't have any value when you use them. Also your comments don't seem to talk about what is going on in your program. To answer your question, if you want to stop at a comma which i guess means you what to break up the string at the comma, then use a for loop to search for the comma, and record the number where the comma is in the string, then you should be able to break up the string how ever you would like. Or you could use some regular expressions to find it and collect the parts of the string you want.


Whats wrong with this c++ program?

I need to output the sum of the square of the odd numbers between firstnum and secnum. I also need to output the sum of all the even numbers between firstnum and secnum.





#include%26lt;iostream%26gt;


#include%26lt;cmath%26gt;


using namespace std;


int main()


{


int firstnum,secnum, i, total=0, a, b;


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


cin%26gt;%26gt;firstnum;


cout%26lt;%26lt;"Enter a second integer (must be less then the first integer enterd):";


cin%26gt;%26gt;secnum;


cout%26lt;%26lt;"your enterd :"%26lt;%26lt;secnum%26lt;%26lt;endl;


if(firstnum%26lt;secnum)


cout%26lt;%26lt;endl;


else


if (firstnum%26gt;secnum)


cout%26lt;%26lt;"Please re-run program and enter numbers again"%26lt;%26lt;endl;


for (i=firstnum; i%26lt;= secnum; i++)


if(i % 2 != 0)


cout %26lt;%26lt; i %26lt;%26lt; " is an odd number between " %26lt;%26lt; firstnum %26lt;%26lt; " and " %26lt;%26lt; secnum %26lt;%26lt; endl;


cout%26lt;%26lt;"The sqrt is"%26lt;%26lt;sqrt(i)%26lt;%26lt;endl;





for (i=firstnum; i%26lt;= secnum; i++)


if(i % 2 == 0)


cout %26lt;%26lt; i %26lt;%26lt; " is an even number between " %26lt;%26lt; firstnum %26lt;%26lt; " and " %26lt;%26lt; secnum %26lt;%26lt; endl;


total += i;


cout %26lt;%26lt; "The total of all even numbers from " %26lt;%26lt; firstnum %26lt;%26lt; " to " %26lt;%26lt; secnum %26lt;%26lt; " is " %26lt;%26lt; total %26lt;%26lt; endl;


cout%26lt;%26lt;"\nPart B"%26lt;%26lt;endl;


a=1;


while(a%26lt;=10)


{


cout%26lt;%26lt;a%26lt;%26lt;" the sqrt "%26lt;%26lt;sqrt(a)%26lt;%26lt;endl;


a=a+1;


}


system("pause");


return 0;

Whats wrong with this c++ program?
There are numerous problems, but I believe these are the three most important ones:





I. It doesn't follow the specification


As written, your program looks like it was supposed to output the following:


1. The odd numbers between firstnum and secnum.


2. The square roots of those numbers.


3. The even numbers between firstnum and secnum.


4. The sum of all the even numbers between firstnum and secnum


5. The square roots of the whole numbers 1 through 10.


Of those 5 things, only one (number 4) is among the things you originally said the program is supposed to output.





II. For loops need correction


If you want several statements to be executed on each iteration of a for loop, you have to put those statements inside curly braces, like this:


for (i = firstnum; i %26lt;= secnum; i++)


{


(the statements go here)


}


Otherwise, only the first statement after the for statement is executed on each iteration of the loop.





III. Numbers aren't squared correctly


If you want the square, as opposed to the square root, of a number a, then you need to use a**2 or a*a, not sqrt(a).


Need help with this C++ program.?

Fill in the blanks in the code below. The program is supposed to


print a triangle of the following shape:


*


**


***


****


***** %26lt;-- This example is for height=5





#include %26lt;iostream%26gt;


using namespace std;





void spaces(int x) {


for (________________________)


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


}





void stars(int x) {


for (_________________________)


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


}





int main() {


int rows;


cout %26lt;%26lt; "How many rows? ";


cin %26gt;%26gt; rows;





for (int star = 1; star %26lt;= rows; star ++) {


spaces (____________________);


stars (_____________________);


cout %26lt;%26lt; endl;


}





}

Need help with this C++ program.?
You should really do your own homework; otherwise, you won't learn anything. However, I'll help you as best I can.





What you seem to have is a procedural program with some functions. (If you don't understand that sentence, look up those terms. They are important. The same applies to any terms you don't understand in this answer)





The first block of code is a function called "spaces". It takes in a single variable: an integer called "x".


What is this block of code supposed to do? It features a for loop that prints out (cout) a single space (" ") each iteration. Clearly you want to control how many spaces are printed out. It seems that "x" is probably important for this.





You've probably been taught in class the way a for loop is supposed to be created, but here's a refresher.


The syntax is:


for( [an initial statement]; [some condition]; [a statement to execute each iteration])


Your initial statement will usually initialize a variable such as "i" which will be used in the loop. Examples of this could be int i=0; int i=x*2; char* i="foo"; bool i = true; or anything else.


Your condition is the terms that must be met for the loop to continue. Usually, this is also in terms of i. For example: i == true; i %26gt;= x; i != 7; etc.


Your final statement is a single line of code that will be executed at the end of the for loop. This is usually something simple like i++, but it could be anything else such as i = i + x or even void * j = %26amp;spaces(i)





Figure out a combination of three statements in terms of x that will make spaces print out the correct number of spaces.





Next is another function called stars. stars looks almost exactly like spaces except that it prints stars ("*") instead of spaces. This part should be easy.





Next comes your main code block. It first asks the user to input a number of rows. Then it goes to another for loop.


This last for loop goes through as many iterations as the user entered (in the example you gave, 5).


Each iteration calls spaces and then stars and then outputs a new line (cout %26lt;%26lt; endl;)


spaces and stars both take in a single argument, right? That single argument is an integer? You need to specify an integer (in terms of the variables "star" and "rows" since those are the only ones you have to work with) that prints out the correct number of stars and spaces.





Good luck!
Reply:if you do a search on answers you'll find this exact program fully written. There are 62 results for "print a triangle". Several of the first are recursive, but many of the rest feature fully written forms of this program.
Reply:First comes your main code block. It first asks the user to input a number of rows. Then it goes to another for loop.


This last for loop goes through as many iterations as the user entered (in the example you gave, 5).


Each iteration calls spaces and then stars and then outputs a new line (cout %26lt;%26lt; endl;)


spaces and stars both take in a single argument, right? That single argument is an integer? You need to specify an integer (in terms of the variables "star" and "rows" since those are the only ones you have to work with) that prints out the correct number of stars and spaces.








give the 10 points to that guy steve up above me!


Need help with a C++ program I'm creating. I thought it would be easy but it's not.?

What is the problem in the following, I cannot run it because it has 17 erros..?????????





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


Radius of a circle


This program calculates the radius of a cirle


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


#include %26lt;iostream%26gt;





using namespace std;





const float PI = 3.141593





int main()


{





float numbera;


float numberb;


float numberc;


float sum;


float radius;


cout %26lt;%26lt; "Enter an integer or a decimal number: ";


cin %26gt;%26gt; numbera;





cout %26lt;%26lt; "Enter a second integer or a decimal number: ";


cin %26gt;%26gt; numberb;





cout %26lt;%26lt; "Enter a third integer or a decimal number: ";


cin %26gt;%26gt; numberc;





sum = numbera + numberb + numberc;


radius = float(sum)/2 * PI;


cout %26lt;%26lt; "The radius is " %26lt;%26lt; radius %26lt;%26lt; endl;





return 0;


}

Need help with a C++ program I'm creating. I thought it would be easy but it's not.?
1.Multi line comments (as you have placed at the top) start with /* and end with */ .


2.Put a semi-colon ( ; ) after the statement:


const float PI = 3.141593


3.You are using the latest ANSI C++ IDE. So, you have to include std: before the cout and cin objects.





The correct program will look something like this:








/* __________ __Your comments_ _________


______here_______ ______ */


#include %26lt;iostream%26gt;





using namespace std;





const float PI = 3.141593;





int main()


{





float numbera;


float numberb;


float numberc;


float sum;


float radius;


std:cout %26lt;%26lt; "Enter an integer or a decimal number: ";


std:cin %26gt;%26gt; numbera;





std:cout %26lt;%26lt; "Enter a second integer or a decimal number: ";


std:cin %26gt;%26gt; numberb;





std:cout %26lt;%26lt; "Enter a third integer or a decimal number: ";


std:cin %26gt;%26gt; numberc;





sum = numbera + numberb + numberc;


radius = (sum/2) * PI;


std:cout %26lt;%26lt; "The radius is " %26lt;%26lt; radius %26lt;%26lt; endl;





return 0;


}





If the const statement doesn't work, just define Pi like this:


#define PI 3.141593


and place it just below the #include %26lt;iostream%26gt; line.





:)
Reply:Don't pay too much attention to the number of errors reported by a compiler. Once they get confused, they tend to stay confused for a bit.





You have a comment which is unterminated. You are missing a semicolon at the end of a statement. These are likely the only two errors you have. I'll let you hunt a bit, rather than giving you the exact answer, as you will need to learn to track these things down.
Reply:u forgot sum semi-colons, getch();





im in ninth grade i took c++ for 1 semister, its over now
Reply:radius = float(sum)/2 * PI;





A while since i've done C++ but i really dont think u should put "float" on that statement.
Reply:#include %26lt;iostream.h%26gt;





dont forget the .h at the end

baseball cards

Need help with this C++ Program?

//table of factorials


#include %26lt;cmath%26gt;


#include %26lt;iostream%26gt;


using namespace std;


int main () {


int n;


cout %26lt;%26lt; "Enter a number: "%26lt;%26lt;endl;


cin %26gt;%26gt; n;


int factorial;


{


return n == 0 ? 1 : n * factorial(n-1);


}


return 0;


}

Need help with this C++ Program?
One way os to recast what you have as a function instead of a main, then call it in a loop, printing out the number and the result of the factorial function each pass through the loop.





A more sophisticated way would be to write a new main consisting of a loop, printing, on each pass through the loop, the number and its factorial (hint: factorial( n ) == factorial( n-1 ) * n).





Good luck. You'll get there.
Reply:just change this main funtion into user functiona and call this function each time from main
Reply:A table? not just a row or column? You could use a loop of some sort, either a 'while' or a 'for', your choice. If you want to list the factorials in ascending order as you build them, have a separate variable that you use to count up to your input number, otherwise, you can use your input number and count down. You can also use the recursion you have here and just have to decide what order to print in. Instead of doing your return on the same line as your calculation, you could do a print after your calculation just before returning, this would print your numbers in ascending order.
Reply:write a new main consisting of a loop, printing, on each pass through the loop, the number and its factorial (hint: factorial( n ) == factorial( n-1 ) * n).
Reply:You should study C++ more because I see a lot of mistakes and poor understanding.





* factorial is not initialized if that was supposed to be a variable.


* you can not have functions inside functions.


* You're returning control and the value to the OS.


* Where are you going to output your results?


* factorial is a variable, but it is being used like a function.


Whats wrong with this c++ program?

When you run this program, you are asked to enter a amount. After entering the amount, it prints the amount you enterd. My problem is if I enter 1.00. The result come up as 1 The .00 does not come up. Anyone know if I have the code wrong or know a way to make this work.





Here is the program





#include%26lt;iostream%26gt;


using namespace std;


int main(void)


{


float purchase;


cout %26lt;%26lt; "Enter the amount purchase $";


cin%26gt;%26gt;purchase;


cout%26lt;%26lt;"the number is $"%26lt;%26lt;purchase%26lt;%26lt;endl;


system("pause");


return 0;


}

Whats wrong with this c++ program?
try using setprecision


cout %26lt;%26lt;"the number is $"%26lt;%26lt;setprecision(2)%26lt;%26lt;purchase%26lt;%26lt;endl;





You might also need:


cout.setf(ios::showpoint);
Reply:Try this:





#include%26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;


int main(void)


{


float purchase;


cout %26lt;%26lt; "Enter the amount purchase $";


cin%26gt;%26gt;purchase;


cout %26lt;%26lt; fixed %26lt;%26lt; showpoint %26lt;%26lt; setprecision(2);


cout%26lt;%26lt;"the number is $"%26lt;%26lt;purchase%26lt;%26lt;endl;


system("pause");


return 0;


}
Reply:That is because of data types. Try using


double purchase;


instead of


float purchase;


and possibly enforce this by saying, after taking input:


purchase=(double) purchase;


or


purchase = purchase / 1.00;


I have written this C++ program but i have 2 problems with this it works just fine but, if you can help me?

I have written this program to convert a integer to binary digit


problem one is that the binary conversion that i get is inverse i.e





if the conversion for 16 is


10000


but this program will output it as


00001


wut function can i use to convert my answer 00001 into 10000


should i use strings fuction get the length of the line than extact each string and use it to get 10000


Or is there a easy way that i can use


but i think the way i did is fine but the problem is that i am getting inverse answer waiting to hear from you thank u





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


using namespace std;





int main ()


{


unsigned int a;


unsigned int y;


a=16;


y=a%2;


a=a/2;


while((a)!=0)


{


cout%26lt;%26lt;y;


y=a%2;


a=a/2;


}


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





return 0;


}

I have written this C++ program but i have 2 problems with this it works just fine but, if you can help me?
Use a integer to string conversion and it will display properly. I had the same problem one time and it worked.


CAN ANYBODY CHECK MY C++ PROGRAM WHAT's wrong with it?

#include %26lt;iostream%26gt;


using namespace std;


void matrix_Multi(const int*matA,const int*matB,const int*matC,int m,int n,int l);


void printArray2(double*,int %26amp;nRow,int %26amp;ncol);


void readArray2( double *, int %26amp;nRow, int %26amp;nCol );








int main()


{


double m,n,l,i,j;


char x;


double *ArrayA,*ArrayB,*ArrayC;


char choice;





do{








std::cout %26lt;%26lt; "Matrix multiplication (A*B):" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "Enter the dimension of matrix" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "A:";


cin%26gt;%26gt;m;


cout%26lt;%26lt;m;


cin%26gt;%26gt;x;


cout%26lt;%26lt;x;


cin%26gt;%26gt;n;


cout%26lt;%26lt;n%26lt;%26lt; std::endl;


ArrayA=new double*m*n;





readArray2(ArrayA,m,n);


std::cout %26lt;%26lt; "Enter the dimension of matrix" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "B:"%26lt;%26lt;n%26lt;%26lt;"x ";


cin%26gt;%26gt;l;


cout%26lt;%26lt;l;


ArrayB=new double*n*l;





readArray2(ArrayB,n,l);


ArrayC=new double*m*l;


matrix_Multi(ArrayA,ArrayB, ArrayC,m,n,l);








printArray2(ArrayC,m,l);





std::cout%26lt;%26lt;"Process another matrix multiplication or Quit(P/Q):";


cin%26gt;%26gt;choice;


cout%26lt;%26lt;choice;





}while(choice=='p'||choice=='P');











return 0;





}




















void readArray2( double *Array, int %26amp;nRow, int %26amp;nCol)





{





int i,j;





cout%26lt;%26lt;"Enter elements of A row by row ("%26lt;%26lt;nCol%26lt;%26lt;" elements per row):"%26lt;%26lt;endl;





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








cout%26lt;%26lt;"Row "%26lt;%26lt;i+1%26lt;%26lt;" "\n";








for(j=0;j%26lt;nCol;j++){








cin%26gt;%26gt;Array[i*nCol+j];





}





while(getchar()!='\n');





}





}
































void printArray2(double *Array,int %26amp;nRow,int %26amp;ncol)





{


int i,j;





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





for(j=0;j%26lt;nCol;j++){





cout%26lt;%26lt;Array[i*nCol+j]%26lt;%26lt;"\t";





}








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


}








}














void matrix_Multi(const int *matA, const int *matB, int *matC, int m, int n, int l)





{





int i,cm,cl;





for(cm=0;cm%26lt;m;cm++){





for(cl=0;cl%26lt;l;cl++){





matC[cm*l+cl]=0;





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





matC[cm*l+cl]+=matA[cm*n+i]*matB[i*l+cl]...





}





}





}





}

CAN ANYBODY CHECK MY C++ PROGRAM WHAT's wrong with it?
I don't know how you got your sample run because the code you posted have a lot of compilations errors.





I fixed them, but since some of the line of your code got cutted by YA I can't really check the result.





Anyway here it is :


#include "stdafx.h"


#include %26lt;iostream%26gt;





using namespace std;


void readArray2( double* Array, int%26amp; nRow, int%26amp; nCol);


void matrix_Multi(const double *matA, const double *matB,


double *matC, int m, int n, int l);


void printArray2(double *Array,int %26amp;nRow,int %26amp;ncol);








int main()


{


int a1,a2;


int b2;


char x;


double *ArrayA,*ArrayB,*ArrayC;


char choice;





do


{


std::cout %26lt;%26lt; "Matrix multiplication (A*B):" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "Enter the dimension of matrix" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "A:";


cin%26gt;%26gt;a1;


cout%26lt;%26lt;a1;


cin%26gt;%26gt;x;


cout%26lt;%26lt;x;


cin%26gt;%26gt;a2;


cout %26lt;%26lt;a2 %26lt;%26lt; std::endl;


ArrayA =new double[a1*a2];





readArray2(ArrayA,a1,a2);


std::cout %26lt;%26lt; "Enter the dimension of matrix" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "B:"%26lt;%26lt; a1 %26lt;%26lt;"x ";


cin%26gt;%26gt; b2;


cout%26lt;%26lt; b2;


ArrayB=new double[a2*b2];





readArray2(ArrayB,a2,b2);


ArrayC=new double[a1*b2];


matrix_Multi(ArrayA,ArrayB, ArrayC,a1,a2,b2);








printArray2(ArrayC,a2,b2);





std::cout%26lt;%26lt;"Process another matrix multiplication or Quit(P/Q):";


cin%26gt;%26gt;choice;


cout%26lt;%26lt;choice;


} while (choice=='p'|| choice=='P');





return 0;


}











void readArray2( double *Array, int %26amp;nRow, int %26amp;nCol)





{


int i,j;


cout%26lt;%26lt;"Enter elements of A row by row ("


%26lt;%26lt;nCol%26lt;%26lt;" elements per row):"%26lt;%26lt;endl;


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


{


cout %26lt;%26lt; "Row " %26lt;%26lt; i+1 %26lt;%26lt; "\n";


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


{


cin%26gt;%26gt;Array[i*nCol+j];


}


while(getchar()!='\n');


}





}








void printArray2(double *Array,int %26amp;nRow,int %26amp;ncol)


{


int i,j;


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


{


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


{


cout%26lt;%26lt;Array[i*ncol+j]%26lt;%26lt;"\t";


}


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


}


}








void matrix_Multi(const double *matA, const double *matB,


double *matC, int m, int n, int l)


{


int i,cm,cl;


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


{


for(cl=0;cl%26lt;l;cl++)


{


matC[cm*l+cl]=0;


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


{


matC[cm*l+cl] += matA[cm*n+i] ; // end of line missing


}


}


}


}
Reply:what is it doing or showing that tells you that something is wrong? are you getting a compiling error, runtime, or just an incorrect answer?

artificial flowers

C++ coding errors?

I'm trying to write a program of polynominal evaluation :





#include%26lt;iostream%26gt;





using namespace std;


float x;


float a[3]={1,2,3};


float p(x);





int main(){





cout%26lt;%26lt; p(1)%26lt;%26lt;endl; // error C2064: term does not evaluate to a function taking 1 arguments


return 0;


}





float p(x){ // error C2448: 'p' : function-style initializer appears to be a function definition


float value=a[2];


for(int i=2;i%26gt;=0;i--)


value=value*x+a[i];


return value;


}

C++ coding errors?
You need a type on the variable x in the function definition/declaration.
Reply:In this code:





float x;


float a[3]={1,2,3};


float p(x);





You need to remove:





float p(x);





Then you need to change your function declaration float p(x) to float p(float x).