我是一个新的相对较新的程序员,我决定用C ++编写代码。目前,我正在开发转换器应用程序项目。我希望从金钱转换到重量到温度,如果可能的话,甚至更多的东西。我写了一段很好的代码,我想检查它是否有效。由于某种原因,代码确实编译但是所有的应用程序确实给了我一个空白的屏幕,没有区域输入值或任何东西。它没有显示我写的指令或其他任何内容。
以下是代码:
#include "std_lib_facilities.h"
int a = 0;
int b = 0;
int c = 0;
int money()
{
cout << "This will convert CAD to either USD or EUR\n";
cout << "Please input USD or EUR followed by an enter keystroke for conversion\n";
string a;
while(cin >> a){
if( a == "USD"){
cout << "If you would like to convert USD into CAD, enter 1.\n";
cout << "If you would like to convert CAD into USD, enter 2.\n";
int x;
cin >> x;
if( x == 1){
cout << "Please enter the amount you wish to convert.\n";
double j;
cin >> j;
double k = j*1.29;
cout << j << "USD is " << k << "CAD.\n";
}
if ( x == 2){
cout << "Please enter the amount you wish to convert.\n";
double o;
cin >> o;
double p = o*0.77;
cout << o << "CAD is " << p << "USD.\n";
}
}
if( a == "EUR"){
cout << "If you would like to convert EUR into CAD, enter 1.\n";
cout << "If you would like to convert CAD into EUR, enter 2.\n";
int y;
cin >> y;
if(y == 1){
cout << "Please enter the amount you wish to convert.\n";
double g;
cin >> g;
double h = g*1.46;
cout << g << "EUR is " << h << "CAD.\n";
}
if(y == 2){
cout << "Please enter the amount you wish to convert.\n";
double z;
cin >> z;
double x = z*0.69;
cout << z << "CAD is " << x << "EUR.\n";
}
}
}
}
int weight()
{
cout << "This will convert pounds to kilograms.\n";
cout << "Please input the amount you wish to convert.\n";
}
int temperature()
{
}
int setup()
{
cout << "Please enter either a,b or c for the corresponding conversions.\n";
cout << "(Where a is for currency, b is for weight, and c is for temperature.\n";
string a;
while ( cin >> a){
if( a == "a"){
int money();
}
if( a == "b"){
int weight();
}
if( a == "c"){
int temperature();
}
}
}
int main()
{
cout << "Welcome to the ultimate converter app.\n";
int setup();
return 0;
}
任何帮助都将不胜感激。
编辑:对每个人来说都很麻烦。感谢所有人,我已经意识到我已经实现了我已经宣布了一项功能,而不是打电话给我。答案 0 :(得分:3)
将class Program < ApplicationRecord
has_many :courses, dependent: :nullify
end
class Course < ApplicationRecord
has_many :sessions, class_name: "CourseSession", inverse_of: :course, dependent: :destroy
belongs_to :program
end
class CourseSession < ApplicationRecord
belongs_to :course
end
替换为int setup();
中的setup();
。
main()
只是声明函数,但不要调用它。
您还必须更正int setup();
:
setup()
void setup()
{
cout << "Please enter either a, b or c for the corresponding conversions." << endl;
cout << "Where a is for currency, b is for weight, and c is for temperature." << endl;
string str;
while (cin >> str) {
if (str == "a") {
money();
}
else if (str == "b") {
weight();
}
else if (str == "c") {
temperature();
}
else {
cout << "Invalid input." << endl;
}
}
}
,money()
和weight()
也必须返回temperature()
类型。
答案 1 :(得分:0)
我认为当你在C ++中调用一个函数时,你只需输入名称(假定它被定义),你不要在函数名之前写一个类型,试试这个...
#include <iostream>
using namespace std;
int a = 0;
int b = 0;
int c = 0;
int money()
{
cout << "This will convert CAD to either USD or EUR\n";
cout << "Please input USD or EUR followed by an enter keystroke for conversion\n";
string a;
while(cin >> a){
if( a == "USD"){
cout << "If you would like to convert USD into CAD, enter 1.\n";
cout << "If you would like to convert CAD into USD, enter 2.\n";
int x;
cin >> x;
if( x == 1){
cout << "Please enter the amount you wish to convert.\n";
double j;
cin >> j;
double k = j*1.29;
cout << j << "USD is " << k << "CAD.\n";
}
if ( x == 2){
cout << "Please enter the amount you wish to convert.\n";
double o;
cin >> o;
double p = o*0.77;
cout << o << "CAD is " << p << "USD.\n";
}
}
if( a == "EUR"){
cout << "If you would like to convert EUR into CAD, enter 1.\n";
cout << "If you would like to convert CAD into EUR, enter 2.\n";
int y;
cin >> y;
if(y == 1){
cout << "Please enter the amount you wish to convert.\n";
double g;
cin >> g;
double h = g*1.46;
cout << g << "EUR is " << h << "CAD.\n";
}
if(y == 2){
cout << "Please enter the amount you wish to convert.\n";
double z;
cin >> z;
double x = z*0.69;
cout << z << "CAD is " << x << "EUR.\n";
}
}
}
}
int weight()
{
cout << "This will convert pounds to kilograms.\n";
cout << "Please input the amount you wish to convert.\n";
}
int temperature()
{
}
int setup()
{
cout << "Please enter either a,b or c for the corresponding conversions.\n";
cout << "(Where a is for currency, b is for weight, and c is for temperature.\n";
string a;
while ( cin >> a){
if( a == "a"){
money();
}
if( a == "b"){
weight();
}
if( a == "c"){
temperature();
}
}
}
int main()
{
cout << "Welcome to the ultimate converter app.\n";
setup();
return 0;
}