C++ throw variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

C++ throw variable

How can i throw a variable in c++? Because whenever i try to do this it gives me an error.

31st Jul 2017, 1:46 PM
Erik Isakov
Erik Isakov - avatar
14 Answers
+ 4
Have look at https://code.sololearn.com/cph9OWr5ZD0Y/?ref=app#cpp Your code has several problems. I tryed to fix them. Your initial problem was to detect the length of the array. In C and C++ this is not so easy. Normally you could put a sentinal value as last entry in the array. In my version, I use the value 0 which is implicit filled with for all not explicit initialized values. Other problems are wrong values used for indexes. In C the first element has index 0. Finally you have to put the right amount of spaces before each line.
1st Aug 2017, 10:07 PM
Manuel Maier
Manuel Maier - avatar
+ 9
Wow thank you all. I really appreciate it.
2nd Aug 2017, 3:40 AM
Erik Isakov
Erik Isakov - avatar
+ 7
I need a variable which is increasing every loop. But the for loop might occur error. There is probably a better way of doing this :/
31st Jul 2017, 1:58 PM
Erik Isakov
Erik Isakov - avatar
+ 7
i already figured out how to get that variable. But there is another problem. https://code.sololearn.com/cp543yXcBJXL/?ref=app
1st Aug 2017, 6:48 AM
Erik Isakov
Erik Isakov - avatar
+ 6
Why would you need to do that?
31st Jul 2017, 1:53 PM
J.G.
J.G. - avatar
+ 6
Hmm. I thought I asked that already. But it appears that the darn thing didn't work again because of the supposed no connection. Anyways, just post the code you have even if it isn't done then we can help you.
31st Jul 2017, 10:53 PM
J.G.
J.G. - avatar
+ 6
it gives four * and lots of spaces instead of a heart
1st Aug 2017, 3:14 PM
Erik Isakov
Erik Isakov - avatar
+ 5
What is the new problem?
1st Aug 2017, 7:49 AM
Daniel
Daniel - avatar
+ 5
Manuel, good, but it doesn't have spaces at the beginning of each line.
1st Aug 2017, 10:10 PM
J.G.
J.G. - avatar
+ 3
Hi @Erik Isakov, usually is easier or better begining something new so I did something based on your code. https://code.sololearn.com/crJfVEoZtSxB/#cpp If it help you, please, tell me, if you need to do changes, change it and if you want to ask again, please, ask us.
3rd Aug 2017, 7:20 AM
Daniel
Daniel - avatar
+ 2
What code did you try? And what is your concrete behavior you like to expect?
31st Jul 2017, 6:29 PM
Manuel Maier
Manuel Maier - avatar
+ 2
Exactly Manuel if Erik gives more detail maybe somebody can help him ;-)
31st Jul 2017, 6:55 PM
Daniel
Daniel - avatar
+ 2
Yes of course. I think that is Erik's part. :) There are different ways to implement it. The easiest i think is to calculate the sum of all stars and spaces in the line and use this value to calculate the need spaces at the beginning of the line.
1st Aug 2017, 10:15 PM
Manuel Maier
Manuel Maier - avatar
+ 2
You are not using some vars correctly. Im trying to do something
1st Aug 2017, 10:34 PM
Daniel
Daniel - avatar