Skela_ 2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
||||
1 |
||||
04.05.2019, 21:22. Показов 8845. Ответов 24 Метки нет (Все метки)
Глупый скела снова здесь! И так, что я опять сделал не так?))
__________________
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 21:29 |
2 |
И так, что я опять сделал не так?)) не попробовали устранить ошибку самостоятельно?
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 21:30 [ТС] |
3 |
попробовали
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 21:32 |
4 |
и как? (как именно попробовали)
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 21:34 [ТС] |
5 |
Да в инете искал, там особо ничего не нашел, пытался как то перекручивать в коде все, setprecision(3) ставил рядом с переменной, типы данных менял, ниче не помогло, я недавно в с++ еще мало чего знаю.
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 21:36 |
6 |
Skela_, как запрос в поисковик формулировали?
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 21:37 [ТС] |
7 |
S_el, Error ‘setprecision’ was not declared in this scope’
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 21:39 |
8 |
Skela_, ок, к этому вернемся чуть позже. Что такое
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 21:41 [ТС] |
9 |
функция что бы установить количество цифр после запятой, наверное
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 21:59 |
10 |
Skela_, а как узнать точно?
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 22:01 [ТС] |
11 |
Спросить у того кто знает?
0 |
817 / 504 / 211 Регистрация: 19.01.2019 Сообщений: 1,196 |
|
04.05.2019, 22:02 |
12 |
S_el, Тут массив интересно объявлен, а вы человека такими вопросами мучаете
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 22:24 [ТС] |
13 |
Кароче я добавил библиотеку <iomanip> и все заработало
0 |
TRam_ зомбяк 1564 / 1213 / 345 Регистрация: 14.05.2017 Сообщений: 3,936 |
||||
04.05.2019, 22:26 |
14 |
|||
Нужно добавить
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 22:27 |
15 |
Тут массив интересно объявлен, а вы человека такими вопросами мучаете Да я человека хоть чему-то научить пытаюсь
Кароче я добавил библиотеку <iomanip> и все заработало А как вы узнали про этот заголовочник?
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 22:38 [ТС] |
16 |
написал setprecision в гугл нашел первую страницу где есть код и нашел библиотеку которой нету у меня
1 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 22:51 |
17 |
Skela_, вот видите — сами смогли решить вопрос.
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 22:53 [ТС] |
18 |
Дааа, только вот оказалось что мне не это надо, я думал оно будет выводить типа 4.60 а на самом деле выводит 4.6, чо делать?)) Только можно без этих вопросов твоих, только время тратит.
0 |
2431 / 1831 / 404 Регистрация: 15.12.2013 Сообщений: 8,166 |
|
04.05.2019, 22:58 |
19 |
Только можно без этих вопросов твоих, только время тратит. Тогда это не ко мне. Мне интересно тебя самому к решению подвести, или самому что-то новое узнать, а дать готовый ответ — нет, уже не интересно. Но на форуме новичков хватает, так что кто-нибудь да откликнется.
0 |
2 / 2 / 0 Регистрация: 04.03.2019 Сообщений: 50 |
|
04.05.2019, 23:17 [ТС] |
20 |
ну давай наводи
0 |
06-30-2010
#1
Registered User
Can someone help me with setprecision?
I am trying to use setprecision but I keep getting the error
Code:
RasMolMaker.cpp:124: error: ‘precision’ was not declared in this scopeI don’t understand why I am getting this error when I include the <iomanip> header. Can someone tell me where I am going wrong? Thanks
BTW, the problem line is at the bottom of the main section at the end of the while loop.
My header file is:
Code:
#include <fstream> #include <iostream> #include <iomanip> #include <string> #include <ios> #include <cstdlib> void writeBash(char* file); void writeCleanup(); void Clearspace(); void clearSpace();and my code is:
Code:
#include "RasMolMaker.h" int main(const int argc, const char** argv) { char ch,holder[100]; const char* c_str(); std::string str,suffix,RasFile; //std::string filename; suffix = ".pdb"; /* // Get filename and open stream std::cout << "Enter filename:n"; std::cin >> filename; std::cout << "Opening " << filename << "...n"; std::ifstream infile; //infile.open(filename.c_str()); */ // Open config file for input std::ifstream infile, infile2; infile.open("config"); // Write formatting bash script char* filename = "config"; writeBash(filename); // Open scratch file for input infile2.open(".17834039BOSUQWU239MBKA89"); /* // Create RasMol file and open stream RasFile = filename + suffix; std::cout << "Output will be to file " << RasFile << "n"; std::ofstream outfile; //outfile.open(RasFile.c_str()); */ // Open config.pdb for output std::ofstream outfile; outfile.open("config.pdb"); // Check files opened correctly if (infile.fail()) { std::cout << "Input file failed to open correctlyn"; } if (outfile.fail()) { std::cout << "Output file failed to open correctlyn"; } if (infile2.fail()) { std::cout << "Scratch file failed to open correctlyn"; } // Find the size of the file infile2.seekg(0, std::ios::end); long len = infile2.tellg(); infile2.seekg(0, std::ios::beg); double x,y,z; int index = 0; while(infile2.tellg() <= (len-2) && infile2.tellg() >=0) { if(index > 0 && index % 3 == 0) { outfile << "n"; }; if (index % 3 == 0 ) { if (index/3 < 10) { if (index/3 % 20 < 10) { outfile << "ATOM " << index/3 << " N" << " "; } else { outfile << "ATOM " << index/3 << " O" << " "; } } if (index/3 >= 10 && index/3 < 100) { if (index/3 % 20 < 10) { outfile << "ATOM " << index/3 << " N" << " "; } else { outfile << "ATOM " << index/3 << " O" << " "; } } if (index/3 >= 100 && index/3 < 1000) { if (index/3 % 20 < 10) { outfile << "ATOM " << index/3 << " N" << " "; } else { outfile << "ATOM " << index/3 << " O" << " "; } } if (index/3 >= 1000 && index/3 < 10000) { if (index/3 % 20 < 10) { outfile << "ATOM " << index/3 << " C" << " "; } else { outfile << "ATOM " << index/3 << " C" << " "; } } } infile2 >> holder; outfile << setprecision(4) << holder << " "; index++; } // Check file position before closing std::cout << "File length: " << len << "n"; std::cout << "File position before closing: " << infile.tellg() << "n"; infile.close(); outfile.close(); writeCleanup(); clearSpace(); return 0; } void writeBash(char* file) { // Open output file stream std::ofstream out; out.open("cleaner.sh"); // Write bash script out << "grep -v 'molecule' " << file << "| grep -v 'BOUNDARY' | grep -v 'MOLECULES' | grep -v 'species' | grep -v 'nMolecule' | grep -v 'orthorhombi' | grep -v 'cubic' | grep -v 'tetragonal' > .17834039BOSUQWU239MBKA89"; // Make script executable std::system("chmod +x cleaner.sh"); // Close filestream out.close(); // Execute script std::system("./cleaner.sh"); } void writeCleanup() { // Open output filestream std::ofstream out; out.open("wipe.sh"); // Write bash script out << "rm .17834039BOSUQWU239MBKA89"; // Make script executable std::system("chmod +x wipe.sh"); // Close filestream out.close(); // Execute script std::system("./wipe.sh"); } void clearSpace() { std::system("rm wipe.sh cleaner.sh"); }
Last edited by waterborne; 06-30-2010 at 01:07 PM.
- Forum
- Beginners
- Not declared in scope error messages
Not declared in scope error messages
Thank you in advance for any assistance. I am working on a final project and I’m writing a program which converts fahrenheit to celsius. I am getting 3 «not declared in scope error messages on lines 25, 27, and 31. I am not sure what I’m doing wrong. This what I have so far.
1. #include <iostream>
2.
3. using namespace std;
4.
5. int main()
6. {
7. double userInput;
8. cout << «Enter Fahrenheit Value: «; // asks for a value to convert
9. do // starts the do loop
10. {
11. cin >> userInput; //user input value
12. cout << «n»; // blank line
13. if (cin.fail() || (userInput > 213) || (userInput < -147)) // defines the range of acceptable user input values
14. {
15. cout << «invalid value, please try again: «; // output when unacceptable value is input
16. cin.clear(); // clear
17. cin.ignore(); // so output doesn’t repeat
18. }
19.
20. } while (cin.fail() || (userInput > 213) || (userInput < -147)); // defines acceptable range of user input values
21.
22. double celsius;
23. celsius = (userInput — 32) *5.0 / 9.0; //sets output formula
24. cout << fixed; //enables for specific decimal precision
25. cout << setprecision(2); //sets precision value to 2 points after the decimal
26. cout << «n»; //blank line
27. cout << internal << showpos << setw(5) << userInput << » Degrees Fahrenheit = » << celsius << » Degrees Celsius. n» << endl << endl; //output display for result calculated with +/- symbol included
28.
29. cout << «Would you like to convert more values?» << endl << endl; //asks to continue or not
30. cout << «Enter ‘Y’ to continue.» << endl << endl; // requires user input to continue or end program
31. cin >> again; //change control variable
32. cout << endl; // spacing for viewing ease
33.
34. }
Last edited on
Okay, first of all, in order to user setw and setprecision, you need to include the iomanip library.
So write this on line 2 (after including iostream) :
#include <iomanip>
31. cin >> again; //change control variable
Then in line 31, you want user to input something and store it in ‘again’ but you have not declared what again is. The compiler doesn’t know what that is if it is a char or a string or an int or a double.
So somewhere before that statement, you need to declare the variable ‘again’.
Hope that helps!
Last edited on
Firstly, the code isn’t particularly readable seeing as you haven’t used code tags or indentation. Secondly, exactly what is out of scope and where have you defined it? For example, you call setprecision(2) on line 25, but it is not defined anywhere in the code you have given.
Newbiee999,
Thanks I really appreciate the help. Your suggestion helped most definitely. I took out line 31, but now after entering «Y» to continue, I can’t figure out how to ask to run line 8 again. My instructions are to use repetitive statements such as DO WHILE, FOR, or IF THEN ELSE to do the conversion again. When I run the program, it does its thing but then after it says to enter «Y» to continue, and I enter «Y», it says process returned. I have to figure out how to get it to ask to re-enter values again after I press «Y». This is what I have now.
1. #include <iostream>
2. #include <iomanip>
3.
4. using namespace std;
5.
6. int main()
7. {
8. double userInput;
9. cout << «Enter Fahrenheit Value: «; // asks for a value to convert
10. do // starts the do loop
11. {
12. cin >> userInput; //user input value
13. cout << «n»; // blank line
14. if (cin.fail() || (userInput > 213) || (userInput < -147)) // defines the range of acceptable user input values
15. {
16. cout << «invalid value, please try again: «; // output when unacceptable value is input
17. cin.clear(); // clear
18. cin.ignore(); // so output doesn’t repeat
19. }
20.
21. } while (cin.fail() || (userInput > 213) || (userInput < -147)); // defines acceptable range of user input values
22.
23. double celsius;
24. celsius = (userInput — 32) *5.0 / 9.0; //sets output formula
25. cout << fixed; //enables for specific decimal precision
26. cout << setprecision(2); //sets precision value to 2 points after the decimal
27. cout << «n»; //blank line
28. cout << internal << showpos << setw(5) << userInput << » Degrees Fahrenheit = » << celsius << » Degrees Celsius. n» << endl << endl; //output display for result calculated with +/- symbol included
29.
30. cout << «Would you like to convert more values?» << endl << endl; //asks to continue or not
31. cout << «Enter ‘Y’ to continue.» << endl << endl; // requires user input to continue or end program
32. cout << «Re-enter values»; //user inputs value again
33. cout << endl; // spacing for viewing ease
34.
35. }
Last edited on
If you put everything that is in main in a while loop which uses a boolean variables which can be set to false if the user wishes to exit, then that should solve the problem. Also code tags are [ code ] and [ /code ] without the spaces. You can use the preview button to check if you’ve done it right. Also, line 21 is pointless, you have a loop and no curly braces so the loop doesn’t do anything.
@ CreasyBear
Ok, what I would suggest is that you before all you code in main, declare a char ‘again’ and set it to ‘Y’ and then put everything in a big while loop that runs only if again = ‘y.
so do something like this:
|
|
I have made changes to only lines 5, 6, and 32.
Hope this helps!
Last edited on
newbiee999,
Thank you very much. That did it. The program is working as intended. I really appreciate all your help. Have a Happy Memorial Day.
Glad I could help
Happy Memorial Day !
Topic archived. No new replies allowed.
Answers 2
vivaan001
Added 12 Jul 2022, 08:17 pm
//You have to include header file
#include <iomanip>
0
Likes
Likes
daniel001
Added 12 Jul 2022, 08:17 pm
int x = 109887;
cout << fixed << setprecision(3) << x;
0
Likes
Likes
More Code Examples
cvtColor source code c++
usaco silver 2019 grass planting solution
best gun in freefire for headshot
c++ sort vector of objects by property
python converter to c
c++ generate random number upper and lower bound
c++ how to do a pointer char to take varols from keyboard
make an x using asterisk c++
Dfs program in c++
c++ excel blank cells
Browse Code Examples
C Language
A programming language.
C++
A programming language.
C#
A programming language.
CSS
The language for styling web pages.
Html
The language for building web pages.
Java
A programming language.
Php
A web server programming language.
Python
A programming language.
Javascript
The language for programming web pages.
Add Answer
|
View In TPC Matrix
Technical Problem Cluster First Answered On
September 23, 2020
Popularity
9/10
Helpfulness
10/10
Contributions From The Grepper Developer Community
Contents
Code Examples
Related Problems
TPC Matrix View Full Screen
‘setprecision’ was not declared in this scope
Comment
10
Popularity
9/10 Helpfulness
10/10
Language
cpp
Source: Grepper
Tags: c++
scope
this
was
Contributed on Sep 23 2020
Sleepy Skimmer
2 Answers Avg Quality 10/10
Grepper
Features
Reviews
Code Answers
Search Code Snippets
Plans & Pricing
FAQ
Welcome
Browsers Supported
Grepper Teams
Documentation
Adding a Code Snippet
Viewing & Copying Snippets
Social
Twitter
LinkedIn
Legal
Privacy Policy
Terms
Contact
support@codegrepper.com