On the first exercise, I wasn't sure what the author meant by...

If you haven't done so already, do the Try this exercises from this chapter. I did all of the examples he showed during this chapter so I don't know if he means that or what.

//2 //converts miles to kilometres double results(double m); int main() { double miles; std::cout << "Convert Miles to Kilometres" <<"\nEnter the speed in miles:\n" <<std::endl; std::cin >> miles; miles = results(miles); } double results(double m) { double km = m * 1.609; std::cout << "That speed is " << km << " kilometres." << std::endl; return km; } //3 int main() { //illegal int double = 0; float age 1; std::string 365_days; double 1name; //legal std::string name1; int number; double customer_change; } //4 /////int int sizecompare(int val1,int val2); int adding(int val1, int val2); int multiply(int val1,int val2); int ratios(int val1, int val2); int main() { int val1; int val2; int total; std::cout << "Enter two numbers" <<std::endl; std::cin >> val1 >> val2; total = sizecompare(val1,val2); std::cout << total << " is larger" << std::endl; total = adding(val1,val2); std::cout << "The sum of the two numbers is " << total << std::endl; total = multiply(val1,val2); std::cout << "Multiplying the two numbers ia: " << total << std::endl; total = ratios(val1,val2); //cout << "The ratio of " << val1 << " and " << val2 << " is 1:" << ratio << '\n'; std::cout << "The ratios of " << val1 << " and " << val2 << std::endl; std::cout << "is " << total << std::endl; } int ratios(int val1,int val2) { int ans; if(val1 < val2) return ans = val1/val2; else if(val1 > val2) return ans = val2/val1; } int multiply(int val1, int val2) { return val1 * val2; } int adding(int val1, int val2) { return val1 + val2; } int sizecompare(int val1,int val2) { if(val1 < val2) return val2; else if(val1 > val2) return val1; } //5 //float float sizecompare(float val1,float val2); float adding(float val1, float val2); float multiply(float val1,float val2); float ratios(float val1, float val2); int main() { float val1; float val2; float total; std::cout << "Enter two numbers" <<std::endl; std::cin >> val1 >> val2; total = sizecompare(val1,val2); std::cout << total << " is larger" << std::endl; total = adding(val1,val2); std::cout << "The sum of the two numbers is " << total << std::endl; total = multiply(val1,val2); std::cout << "Multiplying the two numbers ia: " << total << std::endl; total = ratios(val1,val2); //cout << "The ratio of " << val1 << " and " << val2 << " is 1:" << ratio << '\n'; std::cout << "The ratios of " << val1 << " and " << val2 << std::endl; std::cout << "is " << total << std::endl; } float sizecompare(float val1,float val2) { //https://stackoverflow.com/questions/38333489/c-calculating-the-ratio-of-2-numbers if(val1 < val2) return val2; else if(val1 > val2) return val1; } float multiply(float val1,float val2) { return val1 * val2; } float adding(float val1, float val2) { return val1 + val2; } float ratios(float val1,float val2) { //https://stackoverflow.com/questions/38333489/c-calculating-the-ratio-of-2-numbers float ans; if(val1 < val2) return ans = val1/val2; else if(val1 > val2) return ans = val2/val1; } //Difference is that I can use decimal numbers and its more accurate than integers //6 void Ascending(int n1,int n2,int n3); int main() { int n1,n2,n3; srand(time(NULL)); while(true) { std::cout << "Enter 3 numbers and the program" <<std::endl; std::cout << "will organise them in descending order.\n" <<std::endl; //std::cin >>n1 >>n2 >>n3; n1 = 1+(rand()%3); n2 = 1+(rand()%3); n3 = 1+(rand()%3); std::cout <<"The computer picks: "<<n1<<n2<<n3<<std::endl; Ascending(n1,n2,n3); } } void Ascending(int n1,int n2,int n3) { int temp; if(n1 > n2) { temp = n1; n1 = n2; n2 = temp; } if(n2 > n3) { temp = n2; n2 = n3; n3 = temp; } if(n1 > n2) { temp = n1; n1 = n2; n2 = temp; } std::cout <<"\nSorted numbers are:"<< n1 << ","<<n2 <<","<<n3<<"\n"<<std::endl; Sleep(1000); }

This post has been edited by **albert003**: 12 March 2019 - 02:49 PM