Help! Coding a Program with Limited Knowledge of C/C++

In summary, Toll is set to 100 and Norm is set to 1000. The program is to input two values, toll and norm, and output the results to a file. The file can be overwritten if it already exists.
  • #1
omgitsroy326
30
0
I have a program due in couple hours. Professor expects us to know C++ when we never really went over programming; he expects us to just know it .. anyhow


I have two inputs used with scanf

it's toll and norm

these two values need to be put into a data file created by the program

I need a key that allows me to
create a "data.txt" file and if the file exist to overwrite it by erased etc.. doesn't matter and put in the things as

printf(" Toll = %e \m Norm = %e", toll, norm);

and just exit the program

i know it's coded in C... but that's all i know
anyhow if i can code in C or C++ doesnt' matter also could you tell me what library i can use.
 
Technology news on Phys.org
  • #2


Originally posted by omgitsroy326
I have a program due in couple hours. Professor expects us to know C++ when we never really went over programming; he expects us to just know it .. anyhow


I have two inputs used with scanf

it's toll and norm

these two values need to be put into a data file created by the program

I need a key that allows me to
create a "data.txt" file and if the file exist to overwrite it by erased etc.. doesn't matter and put in the things as

printf(" Toll = %e \m Norm = %e", toll, norm);

and just exit the program

i know it's coded in C... but that's all i know
anyhow if i can code in C or C++ doesnt' matter also could you tell me what library i can use.

Hi omgitsroy

I don't have my C++ book on me, so the syntax may be a bit off.

Code:
#include <fstream> // File operations

.
.
.

ofstream output("data.txt" , ios::out) ; //Opens a file object 'output' to file "data.txt" 
                                         //for output, overwrites if existing

.
.
.

output<<"Toll = "<< toll <<"\m  Norm = "<< norm << endl; //Outputs to file just like 'cout' command

I don't remember how to explicitly close the file, but I don't think it's really necessary unless your program is complex. Formatting can be done with standard i/o commands.

Hope that's all correct...
 
  • #3
thanks a lot
 

Related to Help! Coding a Program with Limited Knowledge of C/C++

1. What is C/C++?

C/C++ is a high-level programming language used for developing a wide range of software applications. It is a general-purpose language, which means it can be used for various purposes, such as creating operating systems, databases, games, and more.

2. How can I learn C/C++ with limited knowledge?

There are various resources available for learning C/C++ with limited knowledge. You can start by reading beginner-friendly books or online tutorials. You can also join online forums or communities where you can ask for help and guidance from experienced programmers.

3. How can I improve my coding skills in C/C++?

Practice is the key to improving your coding skills in any programming language, including C/C++. You can start by working on small projects and gradually move on to more complex ones. Additionally, you can also participate in coding challenges and competitions to challenge yourself and learn from others.

4. What are some common mistakes to avoid while coding in C/C++?

Some common mistakes to avoid while coding in C/C++ include not properly declaring variables, not using comments to explain your code, and not handling errors and exceptions properly. It is also important to follow coding conventions and standards to write clean and readable code.

5. Can I use C/C++ for web development?

Yes, you can use C/C++ for web development, but it is not the most popular choice. C/C++ is more commonly used for developing system software and applications. However, there are some web development frameworks and libraries available for C/C++, such as Wt and CPPCMS, which allow you to build web applications using this language.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
2
Views
404
  • Programming and Computer Science
Replies
30
Views
2K
  • Programming and Computer Science
Replies
8
Views
917
  • Programming and Computer Science
Replies
1
Views
977
  • Programming and Computer Science
Replies
4
Views
760
  • Programming and Computer Science
Replies
4
Views
691
  • Programming and Computer Science
Replies
1
Views
792
  • Programming and Computer Science
Replies
6
Views
2K
Back
Top