簡體   English   中英

不了解變量

[英]Not understanding variables

我的老師給了我們這項作業

開發一個C ++程序,該程序使用變量和cout輸出您的名字,專業,學時數和每學時學費率。
1.使用適當類型的4個變量,這些變量用您的姓名,專業,學分和學費的值初始化。
2.變量名必須是描述性的
3.使用cout將變量的值輸出到控制台。 您的cout語句必須使用4個變量
4.輸出必須標記並且易於閱讀,如下面的示例輸出所示。
5.程序必須記錄以下內容:
一種。 // 名稱
b。 //日期
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;

}

我現在遇到了很多錯誤,而且我現在知道如何解決這些錯誤。 我已附上圖片,其中包含底部的錯誤以及出現的調試錯誤。 有誰知道如何用最基本的術語解決這些問題,我是否為此任務正確使用了變量?

調試錯誤

常規編程錯誤

//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時,您只是遇到了一些問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM