U made some mistakes here :
- You have to write your entire main code inside
int main()
- syntax for using cin is
cin >>
notcin <<
- You dont need to put
char
beforecalavg.str()
because it’s already declared as stringstream - Do not use
using namespace std
. It is a bad practice that could cause a library conflict Why is “using namespace std” considered bad practice?
Code :
#include <iostream>
#include <string>
#include <sstream>
int main()
{
std::cout << "SP2019_Aaron Key - OUTPUT OF USING VARIABLES" << std::endl;
//declares string variable "Word"
char Word;
//Prompts user for word:
std::cout << "Word: ";
//Waits for input for value of "Word" from standard input (keyboard)
std::cin >> Word;
//Declares integer variable "FirstNumber"
double FirstNumber;
//Prompts user for a number:
std::cout << "First Number: ";
//Waits for number:
std::cin >> FirstNumber;
//Declares double variable "SecondNumber":
double SecondNumber;
//Prompts user for a number:
std::cout << "Second Number: ";
//Waits for input:
std::cin >> SecondNumber;
//Adds FirstNumber and SecondNumber:
double SUM = FirstNumber + SecondNumber;
//Calculates Average of FirstNumber and SecondNumber:
double Avg = SUM / 2;
//Gives the average of FirstNumber and SecondNumber:
std::stringstream calavg;
calavg << "The average of " << FirstNumber << " and " << SecondNumber
<< " is: " << Avg;
std::cout << calavg.str();
return 0;
}
8
solved Compiling Issue with C++ [closed]