Sunday, August 2, 2009

C++ fractal program?

This is supposed to be a C++ program that is for (8,0). It prints out the fractal using *'s. Why isn't it working? This is what I have so far:





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


using namespace::std;





using std::cout;





void pattern(int nstars, int startcol);





int main()


{





const int nstars = 8;


int startcol = 0;


pattern (nstars - 32, startcol);


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


{


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


}


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


{


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


}


cout %26lt;%26lt; endl;





}





void pattern (int nstars, int startcol)


{


if(nstars != 0);


}








Please Help!

C++ fractal program?
Look at the code for your pattern function. It doesn't do anything.





You've got for loops elsewhere that look like they should be inside of the pattern function. Why not try moving them, and see if you have better luck.





I suspect you've written too much code at once. Why not start over, and build the code up one step at a time. For example, can you write a version of pattern() that just prints n stars, where n is a function parameter? Once you've done this, it should be easy to expand the code to solve the complete problem.

flowers gifts

How doiwrite a C++ program that reads in a list of prices, program should output theaverageprice andtotalprice

How do I write a C++ program that reads in a list of prices, And the program should output the average price and total price. The price should be properly formatted with a $ and only 2 points past the decimal.

How doiwrite a C++ program that reads in a list of prices, program should output theaverageprice andtotalprice
Show us what you've done so far.





How did you do the input?


How did you store the data internally?


How did you do the calculations?


How did you do the output?





If you haven't even started, you need your own teacher, not us.
Reply:its easy


assign a array and take prices of diffrnt things


add them its total


count no of items


find average


for formatting use ctype.h header with setwidth and setprecision functions


Help with c++ functions program?

Hey i have this c++ program i need to make for school with functions to find the sum average highest lowest and find numbers





here is mine so far.





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


void printAcross (int L[], int size);


void printDown (int L[], int size);


int summation (int L[], int size);


void loadInput (int L[], int size);


float average (int L[], int size);


int largest (int L[], int size);














int main()


{


int A[10] = {0};


cout %26lt;%26lt; "ACROSS: ";


printAcross(A,10);


cout %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; "DOWN: " %26lt;%26lt; endl;


cout %26lt;%26lt; endl;


printDown (A,10);


loadInput (A,10);


int sum;


sum = summation(A,10);


cout %26lt;%26lt; "Sum = " %26lt;%26lt; sum %26lt;%26lt; endl;








return 0;


}





void printAcross(int L[], int size)


{


for (size = 0; size %26lt; 10; size++)


cout %26lt;%26lt; L[size] %26lt;%26lt; " ";


}





void printDown(int L[], int size)


{


for (size = 0; size %26lt; 10; size++)


cout %26lt;%26lt; L[size] %26lt;%26lt; endl;


}





int summation (int L[], int size);


{


for(size = 0; size %26lt; 10; size++


{


sum = sum + L[size];


return sum;


}


void loadInput(i

Help with c++ functions program?
You haven't copied the whole code, it's either has been truncated by Yahoo Editor or you didn't mark it all. Anyway, I have few notes:





* You passed the argument "size" and still haven't made a logical use of it:


- You used it as a control variable!! You don't need to pass variables that you don't need their values and will use just locally and temporarily, you can create them inside the function or let the for loop create it for you, e.g.,


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





- Usually when you have a parameter for an array, you define another parameter of type int to indicate the array's length, "size" variable would have been a good choice, but then you would have to modify the for loops to:





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





what's the point of using a variable rather than the constant integral 10 ?? Let's say you decided to change the array's length, with your way of doing it you will have to go through all the for loops where you typed 10 then change it to the new value, but when using a variable you would just have to change it once.





My suggestion is to declare you array this way:


cont int size = 10;


int A[size] = {0};





.....


// passing the array along with its length


yourArrayFunction ( L, size );





...





then using the constant size in all of your for loops..








*The summation function


-Did you even try to compile the code? I don't see where you have declared the sum variable, declare it just above the for loop and it will be fine, otherwise you will get "undefined variable" compilation error.





- You don't have to declare a variable to store the return value then output it, you can directly use it with cout like this:


cout %26lt;%26lt; "Sum = " %26lt;%26lt; summation(A,10) %26lt;%26lt; endl;








*If your code doesn't fit here, upload it to http://pastebin.com then paste the link you will get here so we can help you with the other functions.
Reply:Try www.amandalasha.blogspot.com there are many different types of programing examples. This may just help. Report It

Reply:You have a question?
Reply:The average is just the sum divided by the number of elements in your array.





For highest and lowest just use a for loop. Go through each element and find the max or min.





Based on your code, you're on a good start and should have the necessary knowledge to finish the other functions.

daylily

How to open a program in C++?

i need to have the user type in the address of the program it wants to open and have it open that. how would i do that in C++ programing

How to open a program in C++?
Why you can't try at


http://expert.hyparoffice.com/
Reply:You'll need to specify what operating system you're using and what you mean by 'address'. We also need to know whether the program is compiled or just source code.





EDIT: The compilation should (according to my understanding) output an executable file which will run like any other program (assuming it's named .exe). It will depend a bit on what compiler you're using though I think.


What happens now when you try to run the program? Make sure you're not having this problem: http://www.gidforums.com/t-4431.html


How to open a program in C++?

i need to have the user type in the address of the program it wants to open and have it open that. how would i do that in C++ programing

How to open a program in C++?
try this





#include %26lt;iostream%26gt;


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


using namespace std;


int main() {


char s1[256],s2[256];


cout%26lt;%26lt;"Program name: ";


gets(s1);


sprintf(s2,"START %s",s1);


const char* prgm=s2;


system(prgm);


}


Can someone help me w/ this program in C++, it is for school.?

Lab 6 Seminar Registration





Create a C++ program that displays the registration information for a programming seminar. The price per person depends on the number of people a company registers. (For example, if a company registers four people, then the amount owed by that company is $400). The following chart shows the charges per registrant.





Number of Registrants Charge per person ($)





1 – 3 150


4 – 9 100


10 or more 90





The program should allow the user to enter the number registered for as many companies as desired. The program should display the total number of people registered, the total charge, and the average charge per registrant.





Sample run:





Enter the number of people registered: 4


Enter the next number of people registered: 2





Output:





The total number of people registered is 6.


The total charge is $700.


The average charge per registrant is $116.67

Can someone help me w/ this program in C++, it is for school.?
#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;





int main()


{


int attendees = 0, totalPrice = 0, classSize = 0;


float aveCharge = 0.0;


string str;





while(true)


{


cout %26lt;%26lt; "Enter the number of people registered from company or 'done' to stop: ";


getline(cin, str);





if (str == "done")


break;


else


attendees = atoi(str.c_str());





classSize += attendees;





if (attendees %26lt;= 3)


{


totalPrice += (attendees * 150);


}


else if (attendees %26lt;= 9)


{


totalPrice += (attendees * 100);


}


else


{


totalPrice += (attendees * 90);


}


}





aveCharge = (float) totalPrice / classSize;





cout %26lt;%26lt; "The total number of people registered is " %26lt;%26lt; classSize %26lt;%26lt; endl;


cout %26lt;%26lt; "The total charge is " %26lt;%26lt; totalPrice %26lt;%26lt; endl;


cout %26lt;%26lt; "The average charge per registrant is " %26lt;%26lt; fixed %26lt;%26lt; setprecision(2) %26lt;%26lt; aveCharge %26lt;%26lt; endl;





return(0);


}
Reply:/* I don't know how you were supposed to solve this (ie, what you already know) but here is a simple solution I used. I took a vector (basically acts like an expandable array) and filled it with values. I then loop thru each of the elements in the vector (the vector%26lt;T%26gt;.at() function accesses the element at that position) and I test for the total charge based on that number. */





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;





int main()


{


std::vector%26lt;int%26gt; peopleRegd; // vector of people registered


int people; // temp input variable





int totalCharge=0;


int totalPeopleRegd=0;





std::cout %26lt;%26lt; "Enter the number of people registered, and enter 0 to quit." %26lt;%26lt; std::endl;





do


{


std::cout %26lt;%26lt; "Enter the number of people registered:";


std::cin %26gt;%26gt; people;


peopleRegd.push_back(people);


} while (people != 0);





// loop thru each registered person


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


{


totalPeopleRegd += peopleRegd.at(i); // add to total person count





if(peopleRegd.at(i) %26gt;= 1 %26amp;%26amp; peopleRegd.at(i) %26lt;= 3)


totalCharge += 150*peopleRegd.at(i);


else if(peopleRegd.at(i) %26gt;= 4 %26amp;%26amp; peopleRegd.at(i) %26lt;= 9)


totalCharge += 100*peopleRegd.at(i);


else


totalCharge += 90*peopleRegd.at(i);


}





std::cout %26lt;%26lt; "The total number of people registered is " %26lt;%26lt; totalPeopleRegd %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "The total charge is $" %26lt;%26lt; totalCharge %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; "The average charge per registrant is $" %26lt;%26lt; ((float)totalCharge)/((float)totalPeople... %26lt;%26lt; std::endl;





return 0;


}


Helping with C++ program to compare the value of two letters. please!?

The Question: What does the following statement print?(All variable are of type int.)





- this is in Visual C++ as well





My code so far:





#include %26lt;iostream%26gt;


using namespace std;





int main ()





{


int j;


int k;





if(j %26lt; k)





if (k %26lt; j)


cout %26lt;%26lt;1;


else


cout %26lt;%26lt;2;





else


if (j %26lt; k)


cout %26lt;%26lt; 3;


else


cout %26lt;%26lt;4;





return 0;


}





It keeps returning to me initialized local variables for j and k. When I use char j and char k, it works fine, but I have to compare them as int. It should print 2 if j %26lt; k and 4 otherwise...





Any help please? I have searched around and can't find anything.





Thank you!








In C++ each letter has a numerical value that goes with it, ex j = 56 and k = 57. So my program needs to compare the letters as integers(to compare there numerical value to see which is larger). but I am not supposed to set there values, and I am not supposed to use type char. Does anyone have any idea?





Thanks in advance.

Helping with C++ program to compare the value of two letters. please!?
The cin fstream object only accepts a character array, so cast them as characters frist. Once they're read from the stream, cast them as numerical then compare.





if ((float)j %26lt; (float)k)


{


cout%26lt;%26lt;3;


}


else


{


cout%26lt;%26lt;4;


}

flamingo plant