当我尝试输出字符串时,它不会在空格后输出文本.它应该询问学生姓名,然后在被问到时输出.这是C++.我没有更多信息要提供,但该网站不会让我发布它所以这句话在这里.
/***************************************************/
/* Author: Sam LaManna */
/* Course: CSC 135 Lisa Frye */
/* Assignment: Program 4 Grade Average */
/* Due Date: 10/10/11 */
/* Filename: program4.cpp */
/* Purpose: Write a program that will process */
/* students are their grades. It will */
/* also read in 10 test scores and */
/* compute their average */
/***************************************************/
#include <iostream> //Basic input/output
#include <iomanip> //Manipulators
using namespace std;
string studname (); //Function declaration for getting students …Run Code Online (Sandbox Code Playgroud) 我在编写一个程序的一部分时遇到了麻烦,该程序将读取一个名称和一个文件中的10个数字.fie称为grades.dat数据文件的结构是:
Number One
99 99 99 99 99 99 99 99 99 99
John Doe
90 99 98 89 87 90.2 87 99 89.3 91
Clark Bar
67 77 65 65.5 66 72 78 62 61 66
Scooby Doo
78 80 77 78 73 74 75 75 76.2 69
Run Code Online (Sandbox Code Playgroud)
这就是我获取数据的功能,我甚至不确定这是否正确.
void input (float& test1, float& test2, float& test3, float& test4, float& test5, float& test6, float& test7, float& test8, float& test9, float& test10, string& studentname)
{
ifstream infile;
infile.open ("grades.dat");
if …Run Code Online (Sandbox Code Playgroud) 我在使用 pow 函数时遇到问题。该方程是A=P*((1+R)/T)^T“^”的幂。我将如何使用 pow 函数,我只看到 4 到 5 次方的示例,与我必须做的完全不同
我尝试使用我询问的do/while循环并在我的一个函数中修复,int main以允许整个程序在用户想要的情况下重新运行,但它重新运行程序而不等待用户输入.
int main()
{
int spoolnumber = 0; // Number of spools to be ordered
float subtotalspool = 0; // Spool sub total
float shippingcost = 0; // Shipping cost
float totalcost = 0; // Total cost
char type = 'n';
do {
instruct(); // Print instructions to user
spoolnumber = spoolnum(); // calculate and store number of spools
subtotalspool = stotalspool(spoolnumber); // Calculate subtotal
shippingcost = shipcost(subtotalspool); // Calculate subtotal
totalcost = tcost(subtotalspool, shippingcost); // Calculate …Run Code Online (Sandbox Code Playgroud) 我想要do while循环来检查输入的输入是否为R OR P.我认为它正在检查两者,当我运行时它到达那个部分暂停一分钟然后我得到"Cpu Limit Exceeded(在另一个相关的说明中,我是否有破坏某些东西的危险?
/************************************************/
/* Name: servcode */
/* Description: Get service type */
/* Parameters: N/A */
/* Return Value: servcode */
/************************************************/
char servcode()
{
char servcode = 'a'; //Define var for service code
char serviceyn = 'n'; //Define var for user verify
int i = 1; //Define var for sentinel loop
do {
cout << "\n" << "\n" << "Please enter your service code, [R]egular or [P]remium:" << "\n";
cin >> servcode;
while ((servcode …Run Code Online (Sandbox Code Playgroud) 我有2个变量,一个值为5,另一个值为0.如果我有:
cout << var1; //the one with a value of 5
cout << var2; //the one with a value of 0
Run Code Online (Sandbox Code Playgroud)
有没有办法让第二个变量在代码中的那个点上的值为0时不打印任何内容?
可能重复:
从C++函数返回多个值
/************************************************/
/* Name: premserv */
/* Description: Calculations for premium serv */
/* Parameters: N/A */
/* Return Value: premserv */
/************************************************/
float premserv ()
{
int daymin = 0; //Var for day minutes
int nightmin = 0; //Var for night minutes
float daytotal = 0; //Var for day total
float nighttotal = 0; //Var for night total
float premserv = 0; //Var for premium service cost
cout << "\n" << "Please enter the number of minutes used …Run Code Online (Sandbox Code Playgroud) 错误:

链接,因为你嵌入时无法使图像更大:http://i.imgur.com/IWJyT.png
我不知道问题是什么.我从未见过之前使用过的格式,所以我发布了一个屏幕截图.
包括整个代码,因为我不知道错误是什么.我没有别的东西可以添加到这个问题,但系统认为我这样做.还有什么我可以添加?
#include <iostream> //Basic input/output
#include <iomanip> //Manipulators
#include <string> //String stuff
#include <fstream>
using namespace std;
void instruct (); //Function declaration for printing instructionstring studname ();
void input (ifstream &infile, float& test1, float& test2, float& test3, float& test4, float& test5, float& test6, float& test7, float& test8, float& test9, float& test10, string& studentname); //Function declaration for input
float aver (float test1, float test2, float test3, float test4, float test5, float test6, float test7, float …Run Code Online (Sandbox Code Playgroud) 我们在Sun OS 5.9上使用Emacs.我在emacs和visual studio中编写了完全相同的代码,并将它们放在unix服务器上的自己的文件夹中.来自emacs的那个编译没有问题,但来自visual studio的那个不会.我在emacs中打开了visual studio版本,它看起来就像我在emacs中创建的那个但它不会编译.编译器是g ++这是代码:
// Samuel LaManna
#include <iostream>
using namespace std;
int main()
{
cout<<endl;
cout<<endl;
cout<<"Hello World!";
cout<<endl;
cout<<endl;
return 0:
}
Run Code Online (Sandbox Code Playgroud)
这些是我在尝试编译visual studio版本时遇到的错误:
Intro.cpp:在函数中
int main()': Intro.cpp:14: error: expected;' 在':'之前令牌Intro.cpp:14:错误:在':'之前预期的primary-expression令牌Intro.cpp:14:错误:期望`;' 之前':'令牌v245-2%
//Samuel LaManna
//Program 1 (intrest rate)
/*Variables:
Principal=P
Interest Rate=R
Times Compounded=T
Answer=A */
#include <iostream> //Input/output
using namespace std;
int main ()
{
int P, R, T, A; //Declaring Variables
cout<<endl;
cout<<"Interest Earned Calculator"; //Prints program title
cout<<endl;
cout<<endl;
cout<<"Please enter the Principal Value: ";
cin >> P;
cout<<endl;
cout<<endl;
cout<<"Please enter the Interest Rate (in decimal form): ";
cin >> R;
cout<<endl;
cout<<endl;
cout<<"Please enter the Number of times the interest is compounded in a year: ";
cin …Run Code Online (Sandbox Code Playgroud) 可能重复:
方程式在C++ 帮助中无法正常工作C++中的
POW函数
在此代码中:
//Samuel LaManna
//Program 1 (intrest rate)
/*Variables:
Principal=P
Interest Rate=R
Times Compounded=T
Savings=S
Interest=I */
#include <iostream> //Input/output
#include <cmath> //Math Functions
using namespace std;
int main ()
{
float P, R, T, S, I; //Declaring Variables
cout<<endl;
cout<<"Interest Earned Calculator"; //Prints program title
cout<<endl;
cout<<endl;
cout<<"Please enter the Principal Value: ";
cin >> P;
cout<<endl;
cout<<endl;
cout<<"Please enter the Interest Rate (in decimal form): ";
cin >> R;
cout<<endl;
cout<<endl;
cout<<"Please enter the …Run Code Online (Sandbox Code Playgroud)