小编Sam*_*nna的帖子

打印带空格的字符串

当我尝试输出字符串时,它不会在空格后输出文本.它应该询问学生姓名,然后在被问到时输出.这是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)

c++

4
推荐指数
1
解决办法
1万
查看次数

如何在C++中拆分行并从中提取值?

我在编写一个程序的一部分时遇到了麻烦,该程序将读取一个名称和一个文件中的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)

c++

2
推荐指数
1
解决办法
109
查看次数

帮助 C++ 中的 POW 函数

我在使用 pow 函数时遇到问题。该方程是A=P*((1+R)/T)^T“^”的幂。我将如何使用 pow 函数,我只看到 4 到 5 次方的示例,与我必须做的完全不同

c++ math

1
推荐指数
1
解决办法
328
查看次数

如何在do/while循环中获取用户输入?

我尝试使用我询问的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)

c++ user-input

1
推荐指数
3
解决办法
6377
查看次数

C++ do/while循环有两个不同的条件

我想要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)

c++

1
推荐指数
1
解决办法
3138
查看次数

C++忽略变量并阻止输出

我有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++

1
推荐指数
1
解决办法
82
查看次数

一种为数组中的所有元素分配相同值的方法

反正有没有这样做?这是我第一次使用数组及其50个元素,我知道它们只会变大.

c++

1
推荐指数
2
解决办法
8760
查看次数

从函数中获取多个值

可能重复:
从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)

c++

0
推荐指数
1
解决办法
208
查看次数

尝试编译文件时出现非常奇怪的错误

错误:

尝试编译时出错

链接,因为你嵌入时无法使图像更大: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)

c++

0
推荐指数
1
解决办法
136
查看次数

在Unix和Visual Studio 2010中创建了相同的程序,Visual Studio不会编译

我们在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%

c++ unix compiler-errors

-1
推荐指数
1
解决办法
198
查看次数

方程在C++中无法正常工作

//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++

-2
推荐指数
1
解决办法
618
查看次数

C++ Float Var四舍五入

可能重复:
方程式在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)

c++

-3
推荐指数
1
解决办法
218
查看次数

标签 统计

c++ ×12

compiler-errors ×1

math ×1

unix ×1

user-input ×1