不理解变量

时间:2016-02-09 19:16:12

标签: c++ string debugging variables

我的导师给了我们这个作业

开发一个C ++程序,使用变量和cout输出您的名字,主要信用小时数和每学分小时的学费率。
1.使用适当类型的4个变量,用您的姓名,专业,学分和学费率的值初始化 2.变量名必须是描述性的 3.使用cout将变量值​​输出到控制台。你的cout声明必须使用4个变量
4.输出必须标记且易于阅读,如下面的示例输出所示 5.程序必须记录如下:
一个。 //姓名
湾//日期
C。 //程序名称
d。 //说明

阅读本章后,我提交了作业。我的代码如下:

//Cassandra Hamric
//January 20, 2016
//Defining Variables
//Outputwill show name, major, credit hours and tuition rate

#include <iostream>
using namespace std;

int main ()
{
int name;
int major;
int hours;
int tuition;
name = Cassandra;
major = Health Information Technology
hours = 16;
tuition = $146.28

cout<<"My name is " << name << endl;
cout<<"I am majoring in " << major <<endl;
cout<<"I am taking" <<hours "credit hours" << endl;
cout<<"I am paying" << tuition "per credit hour" <<endl;
cout<< endl;
system("pause");
return 0;
}

当我提交这个时,我的导师说没有变数,我需要完成任务。我重新阅读了这一章,看了笔记并在网上搜索......这是我提出的新代码......

//Cassandra Hamric
//January 20, 2015
//Defining Variables
//Output will show name, major, credit hours and tuition rate

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string myName;
    string major;
    short credithours;
    float tuitionrate;

    myName = Cassandra;
    major = Health Information Technology;
    credithours = 16;
tuitionrate = $146.28;

cout <<"My name is" << myName << endl;
cout <<"I am majoring in" << major << endl;
cout <<"I am taking" << credithours "credit hours" << endl;
cout <<"I am paying" << tuitionrate "per credit hour" << endl;
cout << endl;
system ("pause");
return 0;

}

我现在有很多错误,我现在知道如何修复它们。我附上了底部错误的图片和我得到的调试错误。有没有人知道如何用最基本的术语解决这些问题,我是否正确地使用变量进行这项任务?

Debugging Error

General Programming Errors

1 个答案:

答案 0 :(得分:4)

//Cassandra Hamric
//January 20, 2015
//Defining Variables
//Output will show name, major, credit hours and tuition rate

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string myName;
    string major;
    short credithours;
    float tuitionrate;

    myName = "Cassandra";
    major = "Health Information Technology";
    credithours = 16;
    tuitionrate = 146.28f;

    cout << "My name is " << myName << endl;
    cout << "I am majoring in " << major << endl;
    cout << "I am taking " << credithours << " credit hours" << endl;
    cout << "I am paying $" << tuitionrate << " per credit hour" << endl;
    cout << endl;
    system("pause");
    return 0;
}

初始化字符串变量和编写cout时,你遇到了一些问题。