- Remove From My Forums
-
Question
-
I got this error and I have no idea what’s causing it. I haven’t been able to find a clear solution online.
Code:
#include <iostream>
using namespace std;int main()
{
int NUM1, NUM2;cout << «Enter your first number: «;
cin >> NUM1;
cout << endl;
cout << «Enter your second number: «;
cin >> NUM2;
cout << endl; cout << endl; //moves cursor two lines downint SUM = NUM1 + NUM2; //Sum
int DIFF = NUM1 — NUM2; //Difference
int PROD = NUM1 * NUM2; //Product
int INT_QUO = NUM1 / NUM2; //Integer quotient
float FLT_QUO = ((float)NUM1) / NUM2; //Float quotientcout << «Sum: » << SUM; cout << endl;
cout << «Difference: » << DIFF; cout << endl;
cout << «Product: » << PROD; cout << endl;
cout << «Integer Quotient: » << INT_QUO; cout << endl;
cout << «Float Quotient: » << FLT_QUO; cout << endl;return 0;
}Help would be appreciated!
Answers
-
I also tried a generic «Hello World» code to the program out and I got the exact same error messages.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << «Hello world!n»;
system(«pause»);
return 0;
}Here’s the full error message:
1>—— Build started: Project: CS215Lab1_01092019, Configuration: Debug Win32 ——
1>HelloWorld.cpp
1>Lab1.cpp
1>c:usersCgrunchsourcereposcs215lab1_01092019cs215lab1_01092019lab1.cpp(8): error C2447: ‘{‘: missing function header (old-style formal list?)
1>c:usersCgrunchsourcereposcs215lab1_01092019cs215lab1_01092019lab1.cpp(10): fatal error C1004: unexpected end-of-file foundThe build output suggests that you have both HelloWorld.cpp and Lab1.cpp
in the same project. The compile errors are from Lab1.cpp so remove that
program from the project and and do a Rebuild with just HelloWorld.cpp in
the project.It would help if you described the steps you followed when creating this
project. Did you start from an Empty Project? Or did you use one of the
supplied templates such as Win32 Console Application?— Wayne
-
Marked as answer by
Thursday, January 10, 2019 5:32 PM
-
Marked as answer by
-
I restarted VS2017 and reopened the Project. VS asked me if I wanted to «normalize line endings» and I clicked «Yes». I removed HelloWorld.cpp and the program works fine now.
Thank you so much for your help!
-
Marked as answer by
CGrunch
Thursday, January 10, 2019 5:32 PM
-
Marked as answer by
Добрый день.
Решаю такую задачку:
«Написать программу с использованием функции, определяющей из двух введённых чисел то,
которое имеет максимальную сумму цифр. Реализовать рекурсивный вариант решения такой задачи.»
Я написал так:
C++ | ||
|
При компиляции в окне Вывод сообщение:
«1>—— Построение начато: проект: 15_Max_summa_chifr, Конфигурация: Debug Win32 ——
1>Компиляция…
1>15_Max_summa_chifr.cpp
1>d:my documentsпрограммирование_информатикаc++15_max_ summa_chifr15_max_summa_chifr.cpp(41) : warning C4996: ‘getch’: The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.
1> c:program files (x86)microsoft visual studio 9.0vcincludeconio.h(145): см. объявление ‘getch’
1>d:my documentsпрограммирование_информатикаc++15_max_ summa_chifr15_max_summa_chifr.cpp(46) : error C2447: {: отсутствует заголовок функции (возможно, используется формальный список старого типа)
1>Журнал построения был сохранен в «file://d:My documentsПрограммирование_ИнформатикаC++15_Max_ summa_chifrDebugBuildLog.htm»
1>15_Max_summa_chifr — ошибок 1, предупреждений 1
========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========»
Как я понимаю, сообщение об ошибке вот это:
«error C2447: {: отсутствует заголовок функции (возможно, используется формальный список старого типа)»
Вообще не понял, что это значит. Подскажите, пожалуйста кто-нибудь.
__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь
Help me solve this error! Thank you very much!
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <math.h>
#include<iostream>
using namespace std;
#define N 2 // number of equations
#define dist 0.1 //step size
#define MIN 0.0 //minimum x
#define MAX 10.0 //maximum x
int main() {
double x, y[N];
//int j;
void runge4(double x, double y[], double step); //header
double f(double x, double y[], int i);
FILE *output; // save data in rk4.dat
output= fopen("rk4.dat","w");
y[0]= 1.0;//initial position
y[1]= 0.0;///initial velocity
fprintf(output, "%f/t%f/n",x,y[0]);
for (x= MIN; x<= MAX; x+= dist) {
runge4(x, y,dist);
fprintf(output,"%f/t%f/n", x, y[0]); //position vs time
}
printf("data stored in rk4.datn");
fclose(output);
} //end of main program
void runge4(double x, double y[], double step);
{ //rk4 subroutine
double f(double x, double y[], int i);
double h = step/2.0
t1[N],t2[N],t3[N],k1[N],k2[N],k3[N],k4[N];
int i;
for (i = 0; i<N; i++) t1[i]=y[i]+0.5*(k1[i]=step*f(x,y,i));
for (i = 0; i<N; i++) t2[i]=y[i]+0.5*(k2[i]=step*f(x+h,t1,i));
for (i = 0; i<N; i++) t3[i]=y[i]+(k3[i]=step*f(x+h,t2,i));
for (i = 0; i<N; i++) k4[i]=step*f(x+step,t3,i);
for (i = 0; i<N; i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;
}
double f(double x, double y[], int i)
{ //RHS equations
if (i==0) return(y[1]); //RHS of first equation
if (i==1) return(-y[0]); //RHS of second equation
}
It’s 4th order runger-kutta solution for harmonic oscillator, i got this from computational physics H.Landau.I don’t know how to fix this, please help me!
Help me solve this error! Thank you very much!
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <math.h>
#include<iostream>
using namespace std;
#define N 2 // number of equations
#define dist 0.1 //step size
#define MIN 0.0 //minimum x
#define MAX 10.0 //maximum x
int main() {
double x, y[N];
//int j;
void runge4(double x, double y[], double step); //header
double f(double x, double y[], int i);
FILE *output; // save data in rk4.dat
output= fopen("rk4.dat","w");
y[0]= 1.0;//initial position
y[1]= 0.0;///initial velocity
fprintf(output, "%f/t%f/n",x,y[0]);
for (x= MIN; x<= MAX; x+= dist) {
runge4(x, y,dist);
fprintf(output,"%f/t%f/n", x, y[0]); //position vs time
}
printf("data stored in rk4.datn");
fclose(output);
} //end of main program
void runge4(double x, double y[], double step);
{ //rk4 subroutine
double f(double x, double y[], int i);
double h = step/2.0
t1[N],t2[N],t3[N],k1[N],k2[N],k3[N],k4[N];
int i;
for (i = 0; i<N; i++) t1[i]=y[i]+0.5*(k1[i]=step*f(x,y,i));
for (i = 0; i<N; i++) t2[i]=y[i]+0.5*(k2[i]=step*f(x+h,t1,i));
for (i = 0; i<N; i++) t3[i]=y[i]+(k3[i]=step*f(x+h,t2,i));
for (i = 0; i<N; i++) k4[i]=step*f(x+step,t3,i);
for (i = 0; i<N; i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;
}
double f(double x, double y[], int i)
{ //RHS equations
if (i==0) return(y[1]); //RHS of first equation
if (i==1) return(-y[0]); //RHS of second equation
}
It’s 4th order runger-kutta solution for harmonic oscillator, i got this from computational physics H.Landau.I don’t know how to fix this, please help me!
Столкнулся с такой задачей, где нужно реализовать свой list
. По примеру из источника я в шаблонный класс включил обычный класс.
template<class T>class List {
class Node {
public:
T d;
Node *next, *prev;
Node(T dat = 0) { d = dat; next = 0; prev = 0; }
};
Node *pbeg, *pend;
public:
List() { pbeg = 0; pend = 0; }
~List();
void add(T d);
Node * find(T i);
Node * insert(T key,T d);
bool remove(T key);
void print();
void print_back();
};
Без методов
Node * find(T i);
Node * insert(T key,T d);
код компилируется, а с ними нет и выдает гору ошибок типа:
Серьезность Код Описание Проект Файл Строка Состояние подавления
Ошибка C2447 {: отсутствует заголовок функции (возможно, используется формальный список старого типа) Шаблонный_класс_вариант2 c:usersсемёнdocumentsvisual studio 2015projectsшаблонный_класс_вариант2шаблонный_класс_вариант2list.h 101
Серьезность Код Описание Проект Файл Строка Состояние подавленияОшибка C2988 неопознанное объявление или определение шаблона Шаблонный_класс_вариант2 c:usersсемёнdocumentsvisual studio 2015projectsшаблонный_класс_вариант2шаблонный_класс_вариант2list.h 99
сама реализация методов:
template<class T> Node* List<T>::find(T i) {
Node *pv = pbeg;
while (pv)
{
if (pv->d == i)
break;
pv = pv->next;
}
return pv;
}
template<class T> Node * List<T>::insert(T key, T d) {
if (Node* pkey = find(key)) {
Node* pv = new Node(d);
pv->next = pkey->next;
pv->prev = pkey;
pkey->next = pv;
if (pkey != pend)
(pv->next)->prev = pv;
else
pend = pv;
return pv;
}
return 0;
}
В чем подвох? Спасибо.