Advertisement



Go Back   Zune Boards > Help Forum > Tech. help

New Member?



 
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Tech. help Come here for help with technology related problems.

Reply
 
LinkBack Thread Tools
Old 09-12-2008, 03:47 PM   #1 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default Carlos Vs C++ - Raging All Day, Every Day!


Quote:
A soft drink company recently surveyed 12,467 of its customers and found that approximately 14 percent of those surveyed purchase one or more energy drinks per week. Of those customers who purchase energy drinks, approximately 64 percent of them prefer citrus flavored energy drinks. Write a program that displays the following:

* The approximate number of customers in the survey who purchased one or more energy drinks per week
* The approximate number of customers in the survey who prefer citrus flavored energy drinks

(problem number 18 page 79)
To complete this program, first: write a flowchart to detail the steps you need to complete the program. Identify the variables and the constants. What type of variables are they? Second: write the program - use the standard format we use in class.
There's the Problem I'm given in Class.

Here's what I have so far;

Code:
// Beginning of Soft Drinks Program
#include<iomanip>
#include <iostream>
using namespace std;

int main()
{
    // Variable Declarations
    int customers = 12467, purchased = 1745, citrus = 7978;
    
    // Display Soft Drink Information
    cout << " Of the " << customers << " that we have surveyedn ";
    cout << " We have found that " << purchased << " have purchased one or more energy drinks per week.n ";
    cout << " While " << citrus << " prefer to only purchase citrus flavored energy drinks ";
    return 0;
}
I don't want anyone to do this for me obviously, but at least explain to me what's going on with it. I'm sure I'm missing something (or even did what I have wrong).

What I have will Compile but it won't Run




Last edited by Carlos : 09-25-2008 at 02:12 PM.



Carlos is offline   Reply With Quote
Old 09-12-2008, 04:01 PM   #2 (permalink)
you lost the game.
zB Programmer
Section Staff
Zune Freak
 
itsnotabigtruck's Avatar
 
Join Date: May 2008
Posts: 1,211
Reputation: 451
Awards Showcase
Best username 
Total Awards: 1
Default

The code looks like it should work, though you should probably be doing the math in the program, like this:

Code:
int n = foo;
float purchasers = bar;
float citrus = baz;

cout << "Respondents: " << n << endl;
cout << "Respondents who purchase energy drinks: " << (int)(n * purchasers) << endl;
cout << "Respondents who prefer citrus: " << (int)(n * citrus * purchasers) << endl;
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

signature by
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




itsnotabigtruck is offline   Reply With Quote
Old 09-12-2008, 04:06 PM   #3 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Quote:
Originally Posted by itsnotabigtruck View Post
The code looks like it should work, though you should probably be doing the math in the program, like this:

Code:
int n = foo;
float purchasers = bar;
float citrus = baz;

cout << "Respondents: " << n << endl;
cout << "Respondents who purchase energy drinks: " << (int)(n * purchasers) << endl;
cout << "Respondents who prefer citrus: " << (int)(n * citrus * purchasers) << endl;
Put that in so now the code is as follows;

Code:
// Beginning of Soft Drinks Program
#include<iomanip>
#include <iostream>
using namespace std;

int main()
{
    // Variable Declarations
    int n = 12467;
    float purchasers = 1745;
    float citrus = 7989;
    
    // Display Soft Drink Information
    cout << "Respondents: " << n << endl;
    cout << "Respondents who purchase energy drinks: " << (int)(n * purchasers) << endl;
    cout << "Respondents who prefer citrus: " << (int)(n * citrus * purchasers) << endl;
    return 0;
}
However it doesn't Run, Compiles just fine though.

Could it be because of my Compiler? I'm using Bloodshed Dev C++.



Carlos is offline   Reply With Quote
Old 09-12-2008, 04:17 PM   #4 (permalink)
you lost the game.
zB Programmer
Section Staff
Zune Freak
 
itsnotabigtruck's Avatar
 
Join Date: May 2008
Posts: 1,211
Reputation: 451
Awards Showcase
Best username 
Total Awards: 1
Default

Quote:
Originally Posted by Carlos View Post
Put that in so now the code is as follows;

Code:
// Beginning of Soft Drinks Program
#include<iomanip>
#include <iostream>
using namespace std;

int main()
{
    // Variable Declarations
    int n = 12467;
    float purchasers = 1745;
    float citrus = 7989;
    
    // Display Soft Drink Information
    cout << "Respondents: " << n << endl;
    cout << "Respondents who purchase energy drinks: " << (int)(n * purchasers) << endl;
    cout << "Respondents who prefer citrus: " << (int)(n * citrus * purchasers) << endl;
    return 0;
}
However it doesn't Run, Compiles just fine though.

Could it be because of my Compiler? I'm using Bloodshed Dev C++.
Run it from the command prompt or add this line before "return 0;":

Code:
cin.ignore();
+rep would be appreciated
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

signature by
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




itsnotabigtruck is offline   Reply With Quote
Old 09-12-2008, 04:21 PM   #5 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Quote:
Originally Posted by itsnotabigtruck View Post
Run it from the command prompt or add this line before "return 0;":

Code:
cin.ignore();
+rep would be appreciated
Thanks so much and enjoy your Rep



Carlos is offline   Reply With Quote
Old 09-25-2008, 02:15 PM   #6 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Alright here's another one that's been giving me trouble;

Quote:
Originally Posted by Assignment
Write a program that asks the user to enter two numbers. the program should use the conditional operator to determine which number is smaller and which is larger.
Here's what I've got so far;

Code:
// Begin Min Max Program
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Declare Variables
    float Numbers;
    float Number_One;
    float Number_Two;
    
    // Input Information
    cout << " Enter Your Numbers : ";
    cin >> Number_One >> Number_Two;
    Numbers = (Number_Two==Number_One) ? 0 : Number_One; // Conditional Operator
    cout << Number_Two << " is larger than " << Number_One << endl;
    cout << Number_One << " is smaller than " << Number_Two << endl;
    system("PAUSE");
    return 0;
}
I get it to say for example;

9 is larger than 2
2 is smaller than 9

If I put in 2 9.

But if I use 9 2 it says

2 is larger than 9
9 is smaller than 2

Last edited by Carlos : 09-25-2008 at 07:40 PM.



Carlos is offline   Reply With Quote
Old 09-25-2008, 07:44 PM   #7 (permalink)
you lost the game.
zB Programmer
Section Staff
Zune Freak
 
itsnotabigtruck's Avatar
 
Join Date: May 2008
Posts: 1,211
Reputation: 451
Awards Showcase
Best username 
Total Awards: 1
Default

Quote:
Originally Posted by Carlos View Post
Alright here's another one that's been giving me trouble;



Here's what I've got so far;
<snip>

I get it to say for example;

9 is larger than 2
2 is smaller than 9

If I put in 2 9.

But if I use 9 2 it says

2 is larger than 9
9 is smaller than 2
I think you need something more like
Code:
if (Number_One == Number_Two)
{
    cout << Number_One << " is equal to " << Number_Two << endl;
}
else
{
    float greater = (Number_One > Number_Two) ? Number_One : Number_Two;
    float lesser = (Number_One < Number_Two) ? Number_One : Number_Two;
    cout << greater << " is greater than " << lesser << endl;
    cout << lesser << " is less than " << greater << endl;
}
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

signature by
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




itsnotabigtruck is offline   Reply With Quote
Old 09-25-2008, 07:48 PM   #8 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Quote:
Originally Posted by itsnotabigtruck View Post
I think you need something more like
Code:
if (Number_One == Number_Two)
{
    cout << Number_One << " is equal to " << Number_Two << endl;
}
else
{
    float greater = (Number_One > Number_Two) ? Number_One : Number_Two;
    float lesser = (Number_One < Number_Two) ? Number_One : Number_Two;
    cout << greater << " is greater than " << lesser << endl;
    cout << lesser << " is less than " << greater << endl;
}

So it should read as;

Code:
// Begin Min Max Program
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Declare Variables
    float Numbers;
    float Number_One;
    float Number_Two;
    
    // Input Information
    if (Number_One == Number_Two)
    {
    cout << Number_One << " is equal to " << Number_Two << endl;
    }
    else
    {
    float greater = (Number_One > Number_Two) ? Number_One : Number_Two;
    float lesser = (Number_One < Number_Two) ? Number_One : Number_Two;
    cout << greater << " is greater than " << lesser << endl;
    cout << lesser << " is less than " << greater << endl;
}
?

The last } is giving me an error though @_@



Carlos is offline   Reply With Quote
Old 09-25-2008, 07:52 PM   #9 (permalink)
you lost the game.
zB Programmer
Section Staff
Zune Freak
 
itsnotabigtruck's Avatar
 
Join Date: May 2008
Posts: 1,211
Reputation: 451
Awards Showcase
Best username 
Total Awards: 1
Default

Quote:
Originally Posted by Carlos View Post
So it should read as;

Code:
// Begin Min Max Program
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Declare Variables
    float Numbers;
    float Number_One;
    float Number_Two;
    
    // Input Information
    if (Number_One == Number_Two)
    {
    cout << Number_One << " is equal to " << Number_Two << endl;
    }
    else
    {
    float greater = (Number_One > Number_Two) ? Number_One : Number_Two;
    float lesser = (Number_One < Number_Two) ? Number_One : Number_Two;
    cout << greater << " is greater than " << lesser << endl;
    cout << lesser << " is less than " << greater << endl;
}
?

The last } is giving me an error though @_@
Missing curly bracket o.O
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

signature by
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




itsnotabigtruck is offline   Reply With Quote
Old 09-25-2008, 07:57 PM   #10 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Quote:
Originally Posted by itsnotabigtruck View Post
Missing curly bracket o.O
Yeah I got that part, however it seems to be adding in random numbers (or at least something).



It should allow the user to put in 2 random numbers (I.E 2 9), thus listing;

2 is smaller than 9
9 is larger than 2

and possibly vice versa (I.E 9 2).



Carlos is offline   Reply With Quote
Old 09-25-2008, 08:15 PM   #11 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

So I finally got the order down, I'm going to sit and understand how it's all done before my brain shuts off.



Carlos is offline   Reply With Quote
Old 10-15-2008, 09:21 AM   #12 (permalink)
The Ragin` Cajun
Support Team
Jr. Staff
Zune Freak
 
Carlos's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 1,107
Reputation: 129
Send a message via AIM to Carlos Send a message via MSN to Carlos Send a message via Yahoo to Carlos Send a message via Skype™ to Carlos
Default

Alright here's a new one;

Quote:
Write a program with a loop that lets the user enter a series of integers. the user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest number entered.
What I got so far;

Code:
#include <iostream>
using namespace std;

int main()
{
    // Declare Constants
    float number
    float numTwenty;
    float numFourty;
    float numSixty;
    float numEighty;
    float numHundred;
    
    // Initiate the Variables
    cout << "Please Enter 5 Integers In The Range Of 1 - 99: ";
    cin >> numTwenty >> numFourty >> numSixty >> numEighty >> numHundred;
    do
    {
        while (number > 50 || number < 50)
        cout
That's all I got so far however I'm wondering should I use the 'do while' loop or use a 'while' as I was going to use originally?

I know what I have so far doesn't work, but I just want to know.

=======

Now that I look at it more, wouldn't a 'For' Loop with Increment and Decrement Operators work as well?

Maybe so. We'll see.

Last edited by Carlos : 10-15-2008 at 09:25 AM.



Carlos is offline   Reply With Quote
Old 10-15-2008, 09:47 AM   #13 (permalink)
God of the Post Reports
Support Team
Section Staff
Super Zuner²
 
Locke's Avatar
 
Join Date: May 2008
Location: In the kitchen, preparing a brand new batch of n00blets
Posts: 3,857
Reputation: 545
Send a message via MSN to Locke
Awards Showcase
Member of the Quarter Biggest staff suck-up Biggest Shouter 
Total Awards: 3
Default

This is what I've gotten:
Code:
#include <iostream>
using namespace std;

int main()
{
    int input, sum(0), driver(1);
    
    cout << "Please Enter Integers In The Range Of 1 - 99:  (Enter -99 to stop)" << endl;
    while(driver == 1)
    {
        cin >> input;
		if (input > 99 || input < 1)
		{
			cout << "Please enter valid input:   (1-99) << endl;
			cin >> input;
		}
		if(input == -99)
			break;
		else
		{
			sum += input;
		}
	}
	
	cout << "The sum of the integers entered is: " << sum << endl;

	return 0;
}
Probably a better way to do it, but that's fully functional. Hope it helps.

EDIT: Shoot, forgot about the 1-99 limit; I'll add it.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Now with links!
Quote:
Originally Posted by Lucifer
Locke: now with higher expectations than most military boot camp instructors.

Last edited by Locke : 10-15-2008 at 10:20 AM.




Locke is offline   Reply With Quote
Old 10-15-2008, 10:02 AM   #14 (permalink)
ad majorem dei gloriam
Administrator
Ultimate Zuner
 
Deiparous's Avatar
 
Join Date: Jan 2007
Posts: 6,600
Reputation: 474
Send a message via AIM to Deiparous Send a message via MSN to Deiparous Send a message via Yahoo to Deiparous Send a message via Skype™ to Deiparous
Awards Showcase
Most Flamboyant Personality 
Total Awards: 1
Default

Quote:
Originally Posted by locke
if(input == -99)
flag == 0;
*cough*
you==fail w/ =

edit:
break=lame
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
is awesome

Last edited by Deiparous : 10-15-2008 at 10:05 AM.



Deiparous is offline   Reply With Quote
Old 10-15-2008, 10:12 AM   #15 (permalink)
God of the Post Reports
Support Team
Section Staff
Super Zuner²