这是我这学期的最后一个项目。当我在replit上运行它时,程序可以运行,但在第一步后就不能完全工作了。当我在VS代码上运行它时,它给了我一个链接器命令错误。这是在3天内完成的,请提供任何帮助。谢谢
下面是我的代码:
`
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
const int HEAD_SPACE = 23;
const int SECND_HDSPACE = 35;
const int THRD_HDSPACE = 27;
char startKey;
char replayKey;
int userChoice;
int main()
{
float conversion(void);
firstStart:
cout << "=======================================================\n\n";
cout << setw(SECND_HDSPACE) << "\t\t\t ::: CURRENCY CONVERTER :::\n\n";
cout << "=======================================================\n\n";
cout << setw(SECND_HDSPACE) << "\t\t\tPlease select any options below\n\n";
cout << setw(SECND_HDSPACE) << "\t\t\t1) Press [1] to convert from USD to GBP\n";
cout << setw(SECND_HDSPACE) << "\t\t\t2) Press [2] to convert from USD to EUR\n";
cout << setw(SECND_HDSPACE) << "\t\t\t3) Press [3] to convert from USD to NZD\n";
cout << setw(SECND_HDSPACE) << "\t\t\t4) Press [4] to convert from USD to JPY\n";
cout << setw(SECND_HDSPACE) << "\t\t\n\n :: PRESS [S] TO START PROGRAM :: \n\n";
menuOption:
cin >> startKey;
if(startKey == 's' && startKey == 'S')
{
float resultVal = conversion();
cout << "The conversion is: " << resultVal << endl;
cout << "Would you like to run the program again? Press Y or N" << endl;
scndStrt:
cin >> replayKey;
if (replayKey == 'y' && replayKey == 'Y')
{
goto firstStart;
}
else if ((replayKey == 'n' && replayKey == 'N'))
{
cout << "Thanks for using my program!" << endl;
}
else
{
cout << "Wrong Key Entered. Please hit Y or N" << endl;
goto scndStrt;
}
}
else
{
cout << "Wrong Key Entered. Please Hit [S]";
goto menuOption;
}
float convervion(void);
int selection;
int currChoice;
float currency1;
float currency2;
cout << "Please enter the currency name: " << endl;
cin >> selection;
cout << "Please enter the amount you would like to convert: " << endl;
cin >> currency1;
switch (selection)
{
case '1':
formulaInput:
cout << "Please enter what currency you would like to conver in: " << endl;
cin >> currency2;
if (currency2 == '1')
{
currency2 = currency1 * 1;
}
else if (currency2 == '2')
{
currency2 = currency1 * 0.84;
}
else if (currency2 == '3')
{
currency2 = currency1 * 0.94;
}
else if (currency2 == '4')
{
currency2 = currency1 * 1.92;
}
else
{
cout << "Incorrect input, please try again." << endl;
goto formulaInput;
}
}
}
`
我试着看了一些视频,但是那些术语和语法对我来说似乎太高级了。我只是一个一年级的计算机科学学生,这是我的第一个学期。
1条答案
按热度按时间56lgkhnf1#
首先,这个程序将无法正常运行。除此之外,还有你的问题:
1.你必须关闭main并打开转换函数。检查所有的花括号是否正确。
1.你的函数声明在main函数里面。正如退休的忍者在评论部分所说的,这是正确的,你可以这样做。请考虑局部和全局作用域。(在main函数里面,它将成为main的局部作用域,而在声明之外,它将成为全局作用域)
但是如果你想一想,如果你在局部作用域中声明的函数下面定义另一个函数,同样的函数无论如何都会变成全局作用域。因此,最好直接在全局作用域中声明函数。现在,只是从这个Angular 来看,为了避免不必要的刺激。
1.您的函数声明和定义中有拼写错误。(conversion /convion)请检查。
1.您的函数声明并定义了一个返回值float,但您忘记了最后的return语句,您需要打印出计算结果。
。