Need Help altering code to desired outcome

Hello all,

I am having difficulties with one of my labs and am racking my brain trying to figure out what to do next. I have tried a while and if loops and cant seem to get it to double the advertisement cost and new_profit correctly can anyone help? I'd greatly appreciate it.

Here are the instructions:

The Rinky Dooflingy Company currently sells 200 dooflingies per month at a profit of $300 per dooflingy. The company now spends $2000 per month on advertising and has a fixed operating cost of $1000 per month that does not depend on volume of sales. If the company doubles the amount spent on advertising, studies show that sales will increase by 20 percent.

Write a program that produces a table with appropriate headings for the amount spent on advertising, the number of sales expected, and the net profit for those sales. Begin with the company’s current status and successively double the amount spent on advertising until the net profit ceases to rise and begins to decline. The output should include the amounts up through the first time the net profit begins to decline. Make sure your output is in dollars and cents.

This is what I have so far:

#include <iostream>
using namespace std;

int main()

{

int ads = 2000;
int sales = 200;
int expenses = 1000;
int profit;
int new_sales;
int new_ads;
int new_profit;

cout << "How business is currently sitting: " << endl;
cout << "You have Sold a Total of " << sales << " Dooflingies." << endl;
cout << "You have Spent a Total of $ "<< endl;
cout << ads << " in Advertising Costs." << endl;
cout << "$" << expenses << " in Operating Costs." << endl;
profit =(sales*300) - expenses;
cout << "and $" << profit << " is your Net Profit" << endl;
cout <<"___________________________________________________________________________________________"<< endl;

while (new_profit > profit)

cout << "After Doubling the Amount Spent in Advertising Dollars, "<< endl;
cout << "This is how the Business is Curently Sitting :" << endl;
new_sales = sales + (sales*.2);
new_ads = ads*2;
cout << "You have Sold a Total of " << new_sales << " Dooflingies." << endl;
cout << "You have Spent a Total of " << endl;
cout << "$" << new_ads << " in Advertising Costs," << endl;
cout << "$" << expenses << " in Operating Costs," << endl;
new_profit =(new_sales*300) - expenses;
cout << "and $" << new_profit << " is your New Net Profit after adjustments" << endl;

return 0;
}




there is no such thing as an if-loop, there are while, for, and do-while loops. They are mostly interchangeable with minor code adjustments to make that happen, so type of loop isnt the problem.

in c++, a code block is defined inside of {} brackets. Without those, loops, conditions, and similar statements only do the NEXT LINE of code (usually, the next statement that has a ; in it but not always). Line of code / statement can have a more complex definition but for now call it a line with a ;.

so you need to move to this format:
while(...
{

}
return 0
}

to start with. See where you get with that... and ask if you get stuck again.

as an aside, if I were doing this, I would have this format:

cout << column_header << colum2 << col3 << etc <<endl; //where you may use tab ('\t') //to make the data align, and put a , after each header

while()
{
//compute values and write out with , after each one
}

return 0

then you can run the program, redirect to a file, and open it in a spreadsheet (thanks to the extra commas). If you don't redirect, it shows on-screen.
Last edited on
Topic archived. No new replies allowed.