Pinhedd :
Wing0 :
I want to pause my program at the end too. system(pause) doesn't work, it tells me that pause is an identifier, and it is undefined.
If you wish to pause the program and wait for the user to press any key to terminate it, append something like the following:
C++:
fprintf(stdout,"Press any key to continue\n");
getchar();
return 0;
getchar is defined in stdio.h / cstdio
EDIT:
A word of advice moving forward. When writing functions, declare all local variables at the top of the function body regardless of whether or not you will use them.
For example, this is a bad programming style
C++:
int a;
fscanf(stdin,"%d",&a);
char *b = "This is a string";
int c;
c = foo(&a,b);
if (c)
{
double d = 1.0f;
a = bar(d);
}
else
{
a = 0;
}
This is a much better programming style
C++:
int a = 0, c = 0;
char *b = "This is a string";
double d = 1.0f;
fscanf(stdin,"%d",&a);
c = foo(&a,b);
if (c)
{
a = bar(d);
}
else
{
a = 0;
}
Space is allocated for local variables all at once when the function is called. It doesn't matter if the function requires 10 bytes of local storage, or 100 bytes of local storage, the time taken to allocate that memory is the same. If you collect all of the declarations at the top of the function body it will make your code much more readable.
Code:
#include "StdAfx.h"
#include <iostream>
#include <string>
#include "stdio.h"
using namespace std;
int main()
{
string movie;
cout << "What is the name of the movie? \n";
getline(cin, movie);
int avg;
int metescore;
int av;
int tomato;
cout << "what is the metascore for " << movie << "? \n";
cin >> metescore;
cout << "What is the tomatoscore for " << movie << "? \n";
cin >> tomato;
av = tomato + metescore;
avg = av / 2;
cout << "The average score for " << movie << " is " << avg << ".";
getchar();
return 0;
}
Ok I added getchar, and all I get when I build is this:
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
Is that because I already built it?
And after I run the program, the debug window shows this:
'Program3.exe': Loaded 'C:\Users\Brady\Documents\Visual Studio 2010\Projects\Program3\Debug\Program3.exe', Symbols loaded.
'Program3.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Program3.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Program3.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Program3.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'Program3.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[3816] Program3.exe: Native' has exited with code 0 (0x0).
And it doesn't pause. I'd assume this means I don't have the library, if so, where can I get it?
And why do some libraries use quotes, and some use arrows?
iostream is #include <iostream>
and StdAfx is #include "StdAfx"
What's the difference?