Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5423
Number of posts: 16952

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I need help w/ this, just beginning and im lost Posted by Michael1220 on 17 Nov 2011 at 5:22 PM
Write a program that allows a user to enter two integer values. Display every whole number that falls between these values.

2. Write a program for a furniture company. Ask the user to choose P for pine, O for oak or M for mahogany. Show the price of a table manufactured with the chosen wood. Prices for pine tables are $100, oak tables are $225 and mahogany tables are $350.
Report
Re: I need help w/ this, just beginning and im lost Posted by bears_in_bowle on 5 Jan 2012 at 8:56 PM
Not sure if you still need this. Here's problem 1.

#include <iostream>

using namespace std;

int main ()
{
    cout << "Enter two values" << endl;
    int a,b;
    cin >> a >> b;
    
    cout << "\n\n\n\n";
    while(a<b){
        cout << a << ", "; //prints number; comma for formatting
        a++; /*raises the value of "a" until it is one less than b, ending the
        loop.*/ 
        }
        cout << b; /* The while loop iterated until one less than b.  We still
        wish to print b. Prints only number with no comma after it*/
        
    int z;
    cin >> z;
    return 0;
    
}

Report
Re: I need help w/ this, just beginning and im lost Posted by bears_in_bowle on 5 Jan 2012 at 8:58 PM
Not sure if you still need this. Here's problem 1.

#include <iostream>

using namespace std;

int main ()
{
    cout << "Enter two values" << endl;
    int a,b;
    cin >> a >> b;
    
    cout << "\n\n\n\n";
    while(a<b){
        cout << a << ", "; //prints number; comma for formatting
        a++; /*raises the value of "a" until it is one less than b, ending the
        loop.*/ 
        }
        cout << b; /* The while loop iterated until one less than b.  We still
        wish to print b. Prints only number with no comma after it*/
        
    int z;
    cin >> z;
    return 0;
    
}

Report
Re: I need help w/ this, just beginning and im lost Posted by Newb1001 on 11 Jan 2012 at 3:49 AM
# include <itream.h>

int main ()

{

int a,b,c;

cout << "enter you values"<<endl;
cin <<a<<b;

Do
{
a= a+1
count <<a<<endl;
a= a+1

}
(while a!=b)


return 0;
}


//this will display all the unit_values between a and b.
Report
Re: I need help w/ this, just beginning and im lost Posted by Newb1001 on 11 Jan 2012 at 4:02 AM
***disregard my last post. This code will work correctly in both cases a<b & a>b [and if a=b it it goes into an infinate loop]***

include <iostream>


int main()
{
int a,b;

cout<< "Enter your values."<<endl;
cin>>a>>b;


if (a<b)
do
{
a=a+1;
cout <<a<< endl;
}
while(a!=b);

else

do
{
a=a-1;
cout <<a<< endl;
}
while(a!=b);

return 0;
}

Report
Re: I need help w/ this, just beginning and im lost Posted by Newb1001 on 11 Jan 2012 at 3:50 AM
# include <itream.h>

int main ()

{

int a,b,c;

cout << "enter you values"<<endl;
cin <<a<<b;

Do
{
a= a+1
count <<a<<endl;
a= a+1

}
(while a!=b)


return 0;
}


//this will display all the unit_values between a and b.
Report
Re: I need help w/ this, just beginning and im lost Posted by Newb1001 on 11 Jan 2012 at 4:24 AM
***Also, I'm trying this approach as a resolve for your question. But I thik its a more appropriate approach to be used for this question***

#include <iostream>

using namespace std;

int main()
{
int a,b,c;
double r;
char ch,o,m,p;

c=0;

cout<< "Enter your spending limit."<<endl;
cin>>b;
cout<< "Please choose between Pine, Oak, Mahoganhi."<<endl;
cin>>ch;

switch(ch)
{



case 'p':

a = 100;
do
{
r=c+a;
cout<<r<<endl;
c=r;
}
while(r!=b);
break;

case 'o':
a=225;

do
{
r=c+a;
cout<<r<<endl;
c=r;
}
while(r!=b);
break;

case 'm':

a=350;
do
{
r=c+a;
cout<<r<<endl;
c=r;
}
while(r!=b);
break;
}


return 0;
}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.