|
Copy and paste?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
i have been trying to make create this program, it's kinda hard for me to get help in real life because I'm the only computer science student in my second semester.
this is c++. I have to use arrays
I have to make a program that shows grades, based on marks. The number of students depends on the user input.
grade A >=90
grade B >=80
grade C >=70
grade D >=60
grade F <=59
based on the homework my lecturer has given me, the output has to be like this
Enter the number of students: 4
Enter 4 marks: 40 55 70 58
student 0 mark is 40 and grade is C
student 1 mark is 55 and grade is B
student 2 mark is 70 and grade is A
student 3 mark is 58 and grade is B
This is my code:
#include<iostream>
using namespace std;
int main(){
int students;
int mark;
int x;
char grade[6]={'A','B','C','D','F','\0'};
cout<<"enter the number of students"<<endl;
cin>>students;
cout<<"enter "<<students<<" marks "<<endl;
for(x=0;x<students;x++){
cin>>mark;
if(mark>=90)
grade[0];
else if(mark>=80)
grade[1];
else if(mark>=70)
grade[2];
else if(mark>=60)
grade[3];
else
grade[4];
cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<grade[x];
}
}
I don't know what to do anymore. Help me
|
|
|
|
|
You have to use arrays. So you should learn about them:
Arrays - C++ Tutorials[^]
std::array - cppreference.com[^]
The example output shows also that you need two loops:
One to read the user input and store it within the array and another one to print the items.
It is up to you what to store in the array: The mark or the grade. Depending on that the conversion has to be done in the first or second loop. But I would store the mark because that is the data entered by the user and is therefore not lost and can be re-used (e.g. when the next task is extending your program).
Because this is homework, you will not get a final solution here. But you should be able to proceed with my above tips.
|
|
|
|
|
if(mark>=90)
grade[0];
The expression in the second line does nothing.
cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<grade[x];
The value of x in the above statement is the loop counter, so it has no relation to the actual grade value you are trying to deal with.
This is fairly basic C/C++ that you need to study and understand.
|
|
|
|
|
Quote: I don't know what to do anymore. Help me
Use the debugger to check what part of your code match your expectations and which part don't, it will help you to marrow the search of defects.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]
C++ Programing Language[^]
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
my english is poor ,so I want to help you ,but I can't tell you in english. we can learn together.
|
|
|
|
|
Hi Friends,
I am using VS2015 and having a solution having 33 VC++ projects. I am using Klocwork insight 11.0 for code analysis work.
while running it, its getting stuck on any of the file. I tried re-installing Klocwork and restarting visual studio as well.
Please help me out if anyone have any idea.
Regards,
Amrit
|
|
|
|
|
|
Hello everybody,
I don't know if I omits something or if I've not correctly understanded something, but I've an Strange exception.
This is the code who generates the exception :
<br />
NetTcpBinding^ binding = gcnew NetTcpBinding();<br />
binding->Name = "IMyWebService";<br />
EndpointAddress^ address = gcnew EndpointAddress("myUrl");<br />
<ChannelFactory<IMyWebService^>^> factory = gcnew ChannelFactory<IMyWebService^>(binding, address);<br />
Exception System.ArgumentNullException occurs on last line.
"All parameter names used in operations that constitute a service contract must be not null. Parameter name : name"
Have you any idea why I'm receiving this exception ?
Many thanks for your help
Best regards,
Syncerely yours,
|
|
|
|
|
You need to use the debugger to examine both of the new objects and see exactly which property is causing the exception.
|
|
|
|
|
Hi,
Thanks for your reply.
Of course. Objects have been examined but no null name parameter was found.
I've tested using configuration file on the Web service to define the service, behavior, ... rather than using code only.
But same error.
Debugger was checked on both side (client / service).
Very strange.
Regards,
Syncerely yours,
|
|
|
|
|
The error message is quite clear, so there must be a null parameter somewhere. It may well be inside the actual framework, caused by something not being built correctl. And the only way to find it is by going deep in the debugger.
|
|
|
|
|
How do I increase size of my tooltip control as I need to show image to my tooltip I probably need to increase size of my tooltip control?
I tried using Text Renderer Measure Text but it just for increasing size according to text we provide.I want to increase size means height and width of my tool Tip so that my whole image gets displayed. Right now only part of image getting displayed using graphics Draw Image function according default size of tool Tip which is small.I am also providing default size of my image by using Graphics Draw Image function.But since size of my toolTip is small only part of image getting displayed.
|
|
|
|
|
|
Thanks.But actually i wanted to modify my toolTip means increase height or width without using HANDLE.Also i tried to create Rectangle using DrawImage function but didnt worked.
|
|
|
|
|
Why not just use a method that works?
|
|
|
|
|
can we use # sign at places other than with the header files
|
|
|
|
|
Yes, you should have #include in your cpp as well. Other uses are the various #pragma s, #define , and is a part of preprocessor operators[^]
Header files are simply to separate definition from implementation generally speaking. They aren't anything special as far as the language itself is concerned.
EDIT: And preprocessor directives[^] in general, just to clarify.
modified 22-Dec-16 12:12pm.
|
|
|
|
|
|
void CreateFolderPath(string Path)
{
char *strFolderPath = new char[Path.size() + 1];
strcpy_s(strFolderPath, Path.size() + 1, Path.c_str());
_mkdir(strFolderPath);
}
string ConvertIntToString(int cipher, int objintiger)
{
string temp;
char *Res = new char[cipher];
sprintf_s(Res, cipher, "%02d", objintiger);
temp = Res;
return temp;
}
//
Is there room for memory problems?
|
|
|
|
|
There are problems (memory leaks). You must delete memory allocated with new when not used anymore:
void CreateFolderPath(string Path)
{
char *strFolderPath = new char[Path.size() + 1];
strcpy_s(strFolderPath, Path.size() + 1, Path.c_str());
_mkdir(strFolderPath);
delete [] strFolderPath;
}
string ConvertIntToString(int cipher, int objintiger)
{
string temp;
char *Res = new char[cipher];
sprintf_s(Res, cipher, "%02d", objintiger);
temp = Res;
delete [] Res;
return temp;
}
For your first example there is even no need to copy the string. Just pass it to _mkdir() :
void CreateFolderPath(string Path)
{
_mkdir(Path.c_str());
}
|
|
|
|
|
Thank you very much!!!!
|
|
|
|
|
hi friends:
why c++ is still being used?!
|
|
|
|
|
Why shouldn't it be used anymore?
Your question is like asking why there are people still driving a Ford.
|
|
|
|
|