novice programm help

Hello I am very new to c++ I need help trying to set a value for a string. The program gives me the error that "info;" *line 13* needs a value *located below "int i;"* Thank you

#include <iostream>
using namespace std;
#include<string>
#include<iomanip>
struct info {
int studentid;
char grade;//capital A,B,C,D,F
};

int main()
{
int i;
info;

cout << "type a studentid \n ";
cin >> info.studentid;
cout << "Type a grade |n";
cin >> info.grade;
cout << "The studentid is" << info.studentid
cout << "The student grade is" << info.grade;
cout << "input an integer|n";
cin >> i;

return 0;

}
info; <--- this is your problem. you forgot to put a variable on info.

try info infovar;
infovar.grade = 'A';




strings can just be assigned.

string s;
s = "whatever";

it is a little more complex to inject variables into the middle of a string, are you ready for that yet?

Last edited on
You need to create a variable of type info.
BTW info is not the most descriptive name, better would be Student sincce the struct holds student data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include<string>
#include<iomanip>

using namespace std;

struct Student
{
  int id;
  char grade;//capital A,B,C,D,F
};

int main()
{
  int i;
  Student student; // create a var student of type Student

  cout << "Type a student id: ";
  cin >> student.id;
  cout << "\nType a grade: ";
  cin >> student.grade;
  cout << "The student id is: " << student.id << "\n";
  cout << "The student grade is: " << student.grade << "\n\n";
  cout << "Input an integer to finish: ";
  cin >> i;

  return 0;
}
closed account (E0p9LyTq)
info is a variable type, like int. You need to create a variable using your type, just as you did with int.

1
2
int i;
info student;


And PLEASE, learn to use code tags, it makes reading your source MUCH easier.
http://www.cplusplus.com/articles/jEywvCM9/

You can edit your post and add code tags.
Topic archived. No new replies allowed.