[Solved] Random Number Gen as function

You need to use if ( (RanNum == 1) || (RanNum == 2) || (RanNum == 3) || (RanNum == 4) || (RanNum == 5) ) instead of if (RanNum = 1||2||3||4||5) Similarly for the other if statement. That’s one problem. The other problem is that you have the line: int RanNum; in main but … Read more

[Solved] C program not printing

Your code is buggy! you don’t allocate memory for the bus[] array, and are trying to access values at garbage location as e.g bus[i] = 0; — Undefined Behavior in C standard, Undefined means you can’t predict how your code will behave at runtime. This code compiled because syntax-wise the code is correct but at … Read more

[Solved] How to pass variables onto another function? [closed]

Just call the function by passing the parameters a, b, and c. Syntax: retval = function_name(parameter1,parameter2,parameter3); //pass parameters as required Like this: int main(void) { float a, b, c; double d; printf(“Enter the values of ‘a’,’b’ and ‘c’: “); if (scanf(“%f %f %f”,&a,&b,&c) == 3) { d = my_function(a, b, c); printf(“Result: %f\n”, d); } … Read more

[Solved] Reading multiple lines of strings from a file and storing it in string array in C++

NumberOfStrings++ is outside of your for loop when you read (i.e. it only gets incremented once). Also please consider using std::vector<std::string> instead of a dynamic array. Here’s a version of your code using std::vector instead of an array: #include <vector> #include <fstream> #include <iostream> #include <string> class StringList { public: StringList(): str(1000000), numberOfStrings(0) { std::ifstream … Read more

[Solved] How to use advance function in swift with three parameters?

That function increments the start index by n positions, but not beyond the end index. Example: You want to truncate strings to a given maximal length: func truncate(string : String, length : Int) -> String { let index = advance(string.startIndex, length, string.endIndex) return string.substringToIndex(index) } println(truncate(“fooBar”, 3)) // foo println(truncate(“fo”, 3)) // fo In the … Read more

[Solved] What is the benefit of using assigning a default value to a parameter in a function in python

It’s because when doing: def calc_tax(sales_total,tax_rate=0.04): print(sales_total * tax_rate) You can do: calc_tax(100) Then here tax_rate is an argument that’s assigned to a default value so can change it by: calc_tax(any thing here,any thing here) OR: calc_tax(any thing here,tax_rate=any thing here) So in the other-hand, this code: def calc_tax(sales_total): print(sales_total*0.04) Is is only able to … Read more