1st Programming Course. Need Help Writing Program

Write your question here.

I've wrestled with this for hours. Help me learn where I've gone wrong and what I can do to make it right & most of all WHY?

Here's the prompt:
Write a C++ program to output information for three students. The information stored in your program contains student’s first name, middle name, last name, and test score. The following shows the information for the three students, where test score (e.g. 78) is in the int type.

John Jacob Smith 78
Mary Jane Weems 82
Dave Joe Dale 61

Your program should declare three named string constants for the three students. Each constant contains the student’s first name, middle name, and last name. You may use three int variables to hold values for the three test scores. The first name, middle name, and last name of a student are then extracted using the substr() function shown in class. Your program should also compute the average (in floating-point number format) for the three test scores. The average score computed should be printed to the screen with 2 digits displayed after the decimal point.

The following shows the output from the program. Note that all the output is left-justified with 15 character positions reserved for each.

first name middle name last name test score average
John Jacob Smith 78 73.67
Mary Jane Weems 82 73.67
Dave Joe Dale 61 73.67

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  
#include "stdafx.h"
#include <iostream>
#include <string>


int main()
{
	const  string1 = "John Jacob Smith = 78";
	const int string2 = "Mary Jane Weems = 82";
	const int string3 = "Dave Joe Dale = 61";

		cout << string1 substr(0, 15);


	return 0;
}

Line 2: the stdafx.h is not needed at all, but <iomanip> is.

Line 9 does not declare the type of the variable, whose name it "string1".

Lines 10 and 11 do declare constant integer variables with names "string2" and "string3", but attempt to initialize them with text, rather than number.

1
2
3
const std::string greeting = "Hello, number";
const int name = 6;
std::cout << greeting << std::setw(2) << name << '\n'


On line 13, if the string1 would have type std::string, then the member function call would require a dot:
cout << string1.substr(0, 15);
It says that you may use 3 integer type to hold three scores. Then,
1
2
3
int score1 = 78;
int score2 = 82;
int score3 = 61;


And constant integers per name
Then,
1
2
3
4
 
const std::string name1 = "Whole name here";
const std::string name2 = "Whole name here";
const std::string name3 = "whole name here";


You may check this sites tutorial about how the data type works
Topic archived. No new replies allowed.