我昨天開始C++,不能爲我的生活找出我做錯了什麼。我正在嘗試製作一個小代碼,它需要用戶輸入三個數字,然後計算每個數字的平方根。試圖找到數字的平方根,但代碼不起作用。 C++
#include "stdafx.h"
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
int squareroot(){ //function to find squareroot.
int sQ1 = sqrt(number1); //variable for the square of number1
int sQ2 = sqrt(number2); //variable for the square of number2
int sQ3 = sqrt(number3); //variable for the square of number3
cout << sQ1 << "\n";//outputs the square of number 1
cout << sQ2 << "\n";//outputs the square of number 2
cout << sQ3 << "\n";//outputs the square of number 3
}
int main() { // main function
int number1 = 0; //first number
int number2 = 0; //second number
int number3 = 0; //third number
cout << "type number1"; //asks user to input first number
cin >> number1; //stores user input into variable number1
cout << "type number2"; //asks for second number
cin >> number2; //stores second number into number2
cout << "type number3"; // asks for third number
cin >> number3; //stores third number
cout << number1 << "\n"; //outputs number1
cout << number2 << "\n"; //ouputs number2
cout << number3 << "\n"; //outputs number3
squareroot(); //runs function squareroot()
}
什麼錯誤信息,你得到什麼?或者,你得到了什麼輸出,你期望輸出什麼?製作[mcve]。作爲'sqrt'結果的'int'是否爲 – nwp
?無論如何,你不清楚你在問什麼。 – tilz0R
你顯示的代碼有什麼問題?它不是建立?你有沒有崩潰?意外的結果?請詳細說明。並請[請閱讀如何提出良好問題](http://stackoverflow.com/help/how-to-ask)。 –