-
Ok i come here to ask for help not for argue. plus i'm not expert on C+ other wise i wont be here.
my high school teacher gave us 20 problem and I'm stuck on this problem
this waht i copy from a black board.
Enter n: 4
6 * 7 = 42
66 * 67 = 4422
666 * 667 = 444222
6666 * 6667 = 44442222
I have to use loop to do it. But this one is so hard i have no idea how to start.
-
Sorry, I don't think any of us understood you the first time, you probably should have told us in the first place :) Ok, here's an idea:
to input, use cin:
Code:
int input;
cin >> input; // now input contains whatever the guy typed.
Here's a idea:
Code:
for(int i = 0; i < input; ++i) //execute this loop (input) times
{
for(int n = 0; n <= i; ++n)
{
cout << "6"; //print the 6's
}
cout << " * ";
for(n = 0; n < i; ++n)
{
cout << "6"; //print the 1st part of 6666...7
}
cout << "7 = "; //print the 7, then " = "
for(n = 0; n <= i; ++n)
{
cout << "4"; //print the 4's
}
for(n = 0; n <= i; ++n)
{
cout << "2"; //print the 2's
}
cout << endl; //new line
}
I just typed this up right now, might not work but it should be enough to get you started (if not finished). I really hope you learn something from this, instead of just copy/pasting like lots of people do.
-
OH
so let me try to understand this
4 is the number of times you need to multiply in some way (which is what you should have told us back on the addition one)
um, i can give you some basic psuedo code, no real code (cause my head hurts at the moment)
take in a variable
for (int i=0;i<thatVariableYouTookIn;i++)
if (i==0)
{
var1=6
var2=7
}
else
{
//do adding to var1 and var2
//seems to add 60, the 600, then 6000 to both variables
}
}
that's about the best i can do for now
[edit]
what hunter did works great, mine would actually multiply stuff...but i don't think you really need to do that.
By the way your c++ class blows, i think your teacher's a moron
[/edit]
-
Well, my method just sort of assumes that whatever the teacher said is right. Basically, it just writes out n 6's, *, n-1 6's, 7, =, then n 4's, then n 2's. Don't know if that's what the teacher wanted, but it should work if the pattern continues :)
-
the problem is he will check each of the program. other wise everyone jsut Cout everything.
Is this a loop or jsut cout.?
float n;
cout<<"ENTER N:";
cin>>n ;
{
cout<<"\t" <<n/2<<"="<<"\t"<<n/2<<"\t";
}
cout<<"\t"<<n/2<<"+"<<n<<"="<<n+n/2;
{
cout<<"\t"<<n/2<<"+"<<n<<"+"<<n+n/2<<"="<<n+n+n;
}
cout<<"\t"<<n/2<<"+"<<n<<"+"<<n+n/2<<"+"<<n+n
<<"="<<n+n+n+n+n;
{
cout<<endl;
}
out put is
2 = 2
2+4 = 6
2+4+6=12
2+4+6+8=20
-
Do you have a horrible teacher?
-
Wow, I guess so... either that or he's bsing. This is a loop:
Code:
for(int i = 0; i < number_of_times_you_want_to_loop; ++i)
{
whatever_you_want_to_do_in_the_loop();
}
And this is another loop:
Code:
while(whatever_has_to_be_true_for_the_loop_to_keep_going)
{
whatever_you_want_to_do_in_the_loop();
}
It's a simple concept, but an important one. If your teacher teaches anything in class, LISTEN TO HIM/HER because otherwise you won't have a clue what to do for you homework; in fact, you sound like one of those people who spend their time pulling the keyboard and mouse cables out of people's computers while the teacher is teaching...
-
>>you sound like one of those people who spend their time pulling the keyboard and mouse cables out of people's computers while the teacher is teaching...
i second that notion