如何在C++中读取值并输出值
How to read the value and output the value in C++
首先,我对C++非常陌生。我的代码有问题。程序应该能够获取/读取用户输入的值并将其输出回来。我尝试了获取/设置C++方法,但在获取和输出main中的值时遇到了一些问题。以下是我的代码,
#include <iostream>
using namespace std;
class Store {
public:
//get and Set Price
void setPrice(int x){
price = x;
}
int getPrice(){
return price;
}
//Get and set % Marked Up
void setPercentageMarkedUp(int y){
markedUpPrice = y;
}
int getPercentageMarkedUp(){
return markedUpPrice;
}
//Get and set percentage Sales tax
void setPercentageSalesTax(int y){
percSalesTax = y;
}
int getPercentageSalesTax(){
return percSalesTax;
}
private:
int price;
int markedUpPrice;
int percSalesTax;
};
int main(){
int price;
Store obj;
cout << "enter the Original Price of the item: "<<endl;
obj.getPrice();
cout<<"the value is:"<<price<<endl;
return 0;
}
由于我对C++和StackOverflow都很陌生,请不要因为我问这个简单的问题而降级。我知道它很基本。一定会感谢那些提供帮助的人。提前谢谢。
只需要如下更新主
int main(){
Store obj;
int n_price;
cout << " Enter Original Price: " << endl;
cin >> n_price;
obj.setPrice(n_price);
cout << "Original Price: " << n_price<< endl;
return 0;
}
谢谢大家。:)
相关文章:
- C++试图读取一个文件并输出到另一个文本文件
- 如何使用C++读取另一个程序中的源代码输出
- 如何读取单个字符并在输入两个字符序列时输出? 使用 while 循环和C++
- 从文件读取并通过矢量输出到控制台
- 从popen()读取的输出是否在pclose()之前完成
- C++ 读取未知数量的整数到 cin 并输出总和
- libmpg123 在我使用整数编码读取 mp3 时强制浮点输出
- 尝试从 txt 文件中读取两条数据并输出它们 [C++]
- 我需要编写一个程序来读取一个文件,该文件将输出所有唯一的整数,如果已经看到整数,它将被关闭
- 将多个效果与 libSox 链接并读取输出数据的正确方法
- 从文件中读取成绩并将平均值输出到另一个文件C++
- 将文本文件读取到2D数组中,但数组开始为超过数组[39][]的任何内容输出胡言乱语
- 如何将批处理文件的输出读取到C 中的字符串中
- C++将 popen 错误输出读取为字符串
- 从控制台输出读取 C++
- 如何在 c++ 中使用二进制文件输入/输出读取/写入结构的字符串类型成员
- 使用Qt从.cmd文件输出读取Echo
- 从标准输出读取奇怪的性能问题
- 如何将QProcess输出读取到QString
- 如何将<string>具有一定数量单词的向量输出读取到一行?