Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours.
#include <iostream>
#include <string>
using namespace std;
int average(int a[]) {
// average function , declaring variable
int i;
char str[40];
float avg = 0;
// iterating in loop
for (i = 0;i < 12;i++)
avg += a[i];
// average calculate and formatting of output
avg = avg / 12;
getline(str, "%.2f", avg);
getline(str, "%f", &avg);
// printing output
cout << "The average score is " << str
<< endl;
}
int highest(int a[]) {
// highest function
int i, high = 0;
for (i = 0;i < 12;i++) {
// taking greatest Number from
array
if (a[i] > high)
high =
a[i];
}
// printing output
cout << "The highest score is " << high
<< endl;
}
int low(int a[]) {
// low calculate function
int i, lowest = 101;
for (i = 0;i < 12;i++) {
// if lower than lowest
if (a[i] < lowest)
lowest =
a[i];
}
// printing output
cout << "The lowest score is " << lowest
<< endl;
}
int pass(int a[])
{
// declaring variable
int i, passed = 0;
for (i = 0;i < 12;i++) {
if (a[i] >= 60)
passed +=
1;
}
// printing output
cout << "Number of students who passed: "
<< passed << endl;
}
int fail(int a[])
{
// declaring variable
int i, failed = 0;
for (i = 0;i < 12;i++) {
if (a[i] < 60)
failed += 1;
}
// printing output
cout << "Number of students who failed: "
<< failed << endl;
}
int graded(int a[])
{
// declaring variable grades
int i, A = 0, B = 0, C = 0, D = 0, F = 0;
for (i = 0;i < 12;i++) {
// depending upon marks increasing
grade
if (a[i] >= 90)
A += 1;
else if (a[i] >= 80 &&
a[i] <= 89)
B += 1;
else if (a[i] >= 70 &&
a[i] <= 79)
C += 1;
else if (a[i] >= 60 &&
a[i] <= 69)
D += 1;
else
F += 1;
}
// printing output
cout << "The number of exams represented by each
letter grade is as follows:" << endl;
cout << "A's:" << A << endl;
cout << "B's:" << B << endl;
cout << "C's:" << C << endl;
cout << "D's:" << D << endl;
cout << "F's:" << F << endl;
return 0;
}
int main()
{
// Declaring variables
int a[12], i, j;
string name;
char choice;
do {
// Taking input as exam name
cout << "Please Enter the
name of the exam:?";
getline(cin, name);
// Taking marks as input
for (i = 0;i < 12;i++) {
cout <<
"Enter score " << i + 1 << ";?";
cin >>
a[i];
// validating
marks
if (a[i] >= 0
and a[i] <= 100) {
continue;
}
else {
i--;
cout << "Please Enter the correct marks
between 0 and 100" << endl;
}
}
// printing desired output
cout << "The score of "
<< name << " are:" << endl;
for (i = 0;i < 12;i++)
// printing
marks
cout <<
a[i] << " ";
cout << endl;
// calling various funcctions
average(a);
highest(a);
low(a);
pass(a);
fail(a);
graded(a);
// taking input for
continuation
cout << "Would you like to
calculate the average for another exam? <Y or N> ";
cin >> choice;
// validating choice
} while (choice == 'y' || choice == 'Y');
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int average(int a[]) {
// average function , declaring variable
int i;
char str[40];
float avg = 0;
// iterating in loop
for (i = 0;i < 12;i++)
avg += a[i];
// average calculate and formatting of output
avg = avg / 12;
//getline(str, "%.2f", avg);
//getline(str, "%f", &avg);
// printing output
cout << "The average score is " << avg <<
endl;
return avg;
}
int highest(int a[]) {
// highest function
int i, high = 0;
for (i = 0;i < 12;i++) {
// taking greatest Number from array
if (a[i] > high)
high = a[i];
}
// printing output
cout << "The highest score is " << high <<
endl;
return high;
}
int low(int a[]) {
// low calculate function
int i, lowest = 101;
for (i = 0;i < 12;i++) {
// if lower than lowest
if (a[i] < lowest)
lowest = a[i];
}
// printing output
cout << "The lowest score is " << lowest <<
endl;
return lowest;
}
int pass(int a[])
{
// declaring variable
int i, passed = 0;
for (i = 0;i < 12;i++) {
if (a[i] >= 60)
passed += 1;
}
// printing output
cout << "Number of students who passed: " << passed
<< endl;
}
int fail(int a[])
{
// declaring variable
int i, failed = 0;
for (i = 0;i < 12;i++) {
if (a[i] < 60)
failed += 1;
}
// printing output
cout << "Number of students who failed: " << failed
<< endl;
}
int graded(int a[])
{
// declaring variable grades
int i, A = 0, B = 0, C = 0, D = 0, F = 0;
for (i = 0;i < 12;i++) {
// depending upon marks increasing grade
if (a[i] >= 90)
A += 1;
else if (a[i] >= 80 && a[i] <= 89)
B += 1;
else if (a[i] >= 70 && a[i] <= 79)
C += 1;
else if (a[i] >= 60 && a[i] <= 69)
D += 1;
else
F += 1;
}
// printing output
cout << "The number of exams represented by each letter grade
is as follows:" << endl;
cout << "A's:" << A << endl;
cout << "B's:" << B << endl;
cout << "C's:" << C << endl;
cout << "D's:" << D << endl;
cout << "F's:" << F << endl;
return 0;
}
int main()
{
// Declaring variables
int a[12], i, j;
string name;
char choice;
do {
// Taking input as exam name
cout << "Please Enter the name of the exam:?";
getline(cin, name);
// Taking marks as input
for (i = 0;i < 12;i++) {
cout << "Enter score " << i + 1 << ";?";
cin >> a[i];
// validating marks
if (a[i] >= 0 and a[i] <= 100) {
continue;
}
else {
i--;
cout << "Please Enter the correct marks between 0 and 100"
<< endl;
}
}
// printing desired output
cout << "The score of " << name << " are:"
<< endl;
for (i = 0;i < 12;i++)
// printing marks
cout << a[i] << " ";
cout << endl;
// calling various funcctions
average(a);
highest(a);
low(a);
pass(a);
fail(a);
graded(a);
// taking input for continuation
cout << "Would you like to calculate the average for another
exam? <Y or N> ";
cin >> choice;
// validating choice
} while (choice == 'y' || choice == 'Y');
return 0;
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Need help with a C++ program. I have been getting the error "this function or variable...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() { int n; double avg, sum = 0;; string in_file, out_file; cout << "Please enter the name of the input file: "; cin >> in_file; ...
The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2; The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical. The program is as follows: Ch. 11, Assignment #3. pg. 646. Program #4. //Weather Statistics. //Write a program that uses a structure to store the...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
I'm not getting out put what should I do I have 3 text files which is in same folder with main program. I have attached program with it too. please help me with this. ------------------------------------------------------------------------------------ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the...
C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...
I need help in my C++ code regarding outputting the enums in string chars. I created a switch statement for the enums in order to output words instead of their respective enumerated values, but an error came up regarding a "cout" operator on my "Type of Item" line in my ranged-based for loop near the bottom of the code. I tried casting "i.type" to both "i.GroceryItem::Section::type" and "i.Section::type", but neither worked. Simply put, if a user inputs 1 as their...
I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...